谁能告诉我这是为什么?

来源:互联网 发布:知托付 编辑:程序博客网 时间:2024/05/01 06:24

require_gem "mysql"
begin
  dbh=Mysql.real_connect("localhost","root","admin","test",3306)
  dbh.query("drop table if exists test_rb")
  dbh.query("create table test_rb(id int,name varchar(20))")
  dbh.query("insert into test_rb values(1,'ss')")
  dbh.query("insert into test_rb values(1,'aaa')")
  printf "%d rows were inserted/n",dbh.affected_rows
 
  res=dbh.query("SELECT name FROM test_rb")
  puts "===============/n"
  while row=res.fetch_row do
  printf "%s,%s/n",row[0],row[1]
  end
  puts "================/n"
  puts "Server version:"+dbh.get_server_info
  rescue Mysql::Error=>e
  puts "Error code:#{e.errno}"
  puts "Error message:#{e.error}"
  puts "Error SQLSTATE:#{e.sqlstate}" if e.respond_to?("sqlstate")
  ensure
  dbh.close if dbh
 end

今天在网上找了这个程序.

原来的是require "mysql"这些东西,提示 uninitialized constant Mysql (NameError)这个错误.改成这个以后require_gem "mysql"就没问题了.

因为是新手不知何解.

 
原创粉丝点击