drkjzk3359 2016-11-25 22:16
浏览 43
已采纳

是否有一个与php mysql_real_escape_string()平行的好ruby

I'm currently working on a project that has ruby at one end with a mysql database and a php presentation on another side. I'd really like to be able to push content to the db with ruby and then pull it out with php. The content is json encoded right now, but I'd like to be able to escape the strings the same way at both ends so that I'm not getting stuck with a bunch of artifacts.

Any suggestions would be really appreciated.

  • 写回答

1条回答 默认 最新

  • duanfu3390 2016-11-25 22:30
    关注

    The answer in Ruby is to avoid using the low-level driver like mysql2 and instead use a database layer like Sequel or ActiveRecord which comes bundled with Rails.

    Sequel is the most no-nonsense option of these two and it allows you to write statements with placeholder values:

    INSERT INTO my_table (name, on_date) VALUES (?,?)
    

    That way your data is added after the fact using bindings and escaping is handled for you automatically. This is the safest way to do it.

    If you do need to do manual escaping, do it in a way that's as obvious as possible since getting this wrong can expose you to huge risks.

    PHP has a terrible reputation for taking a cavalier approach to writing database calls. Ruby's approach, like that in the Python world, is much more orderly and encourages the use of higher-level abstractions when writing database code.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效