当我尝试通过Ruby连接到数据库时,出现此错误:
conn.rb:16:in `<main>': undefined method `query=' for #<Mysql2::Client:0x2ee5190> (NoMethodError)
Did you mean? query
_query
我的代码是:
require 'mysql2'
connection = Mysql2::Client.new(:host => "localhost", :username => "root",:password => "",:database => "ruby")
result = connection.query = ("INSERT INTO datacheck(#{info.keys}) VALUES #{info.values}")
直到这一行似乎一切正常
result = connection.query = ("INSERT INTO datacheck(#{info.keys}) VALUES #{info.values}")
我正在寻找可以提供帮助的人。
答案 0 :(得分:2)
错误消息非常清楚:它不存在query=
方法,但是query
存在。试试
result = connection.query("INSERT INTO datacheck(#{info.keys}) VALUES #{info.values}")