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.

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

报告相同问题?

悬赏问题

  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥200 关于#c++#的问题,请各位专家解答!网站的邀请码
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号