
con = MysqL2::ClIEnt.new(:host => "#{ENV['DB_HOST']}",:port => '3306',:username => "#{ENV['DB_Uname']}",:password => "#{ENV['DB_PWD']}",:database => 'dbname')解决方法 不幸的是,MysqL2 gem尚未准备好语句支持.贡献者计划在不久的将来添加这样的功能,正如我们从Pull Request讨论中看到的那样: https://github.com/brianmario/mysql2/pull/289
如果您的应用程序中必须准备好语句,我建议您阅读Sequel,它对预准备语句和绑定变量有很好的支持:
https://github.com/jeremyevans/sequel
http://sequel.jeremyevans.net/rdoc/files/doc/prepared_statements_rdoc.html
UPDATE
正如@lulalala在版本0.4.0 MySQL2 gem上提到的那样,支持预备语句:
statement = @clIEnt.prepare("SELECT * FROM users WHERE login_count = ?")result1 = statement.execute(1) # Binds the value 1 to the placeholder result2 = statement.execute(2) # Binds the value 2 to the placeholderstatement = @clIEnt.prepare("SELECT * FROM users WHERE last_login >= ? AND location liKE ?")result = statement.execute(1,"CA") # Binds 1 and 'CA' to the placeholders,respectively 我希望有所帮助.
总结以上是内存溢出为你收集整理的ruby – 使用带有MySQL2 gem的预处理语句?全部内容,希望文章能够帮你解决ruby – 使用带有MySQL2 gem的预处理语句?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)