ruby访问mysql,报mysql_api.so (LoadError)

转自: http://hi.baidu.com/vincent%CE%E4/blog/item/98d63d2929bfc320d52af143.html

报mysql_api.so (LoadError),上网查了后发现ruby操作数据库还有一些特别的东西,把mysql安装目录下的libmySQL.dll拷贝到ruby安装目录的bin下,再次运行,可以连上数据库了。 require 'rubygems' require 'mysql' def with_db dbh=Mysql.real_connect('localhost','root','root','dedecmsv56gbk',3306) begin yield dbh rescue MysqlError => e print "Error code: ", e.errno, "\n" print "Error message: ", e.error, "\n" ensure dbh.close end end with_db do |db| res = db.query('select * from dede_addonarticle') res.each {|row| puts "#{row.to_s}"} res.free end

你可能感兴趣的:(html,mysql,Blog,Ruby,rubygems)