普通网友 2018-02-18 04:26
浏览 42
已采纳

阻止在laravel查询构建器上对数据库执行insert语句

I have query builder method like this:

 public function export_excel($query)
    {
      return DB::select(DB::raw($query));
    } 

I want to execute select statements not insert or update statements

  • 写回答

1条回答 默认 最新

  • douqi2571 2018-02-18 04:59
    关注

    You can parse the $query checking for unwanted INSERT/UPDATE/etc. with a sql parser.

    Pear: http://pear.php.net/package/SQL_Parser (still fairly new)

    txtSQL: http://sourceforge.net/projects/txtsql

    PHP-SQL-Parse: http://code.google.com/p/php-sql-parser/ (as mentioned by the OP). This seems to be the most robust of these three (certainly the best documented)

    from sql-parser-in-php.

    But as pointed from @AlonEitan Transaction and Rollback could do the the jobs, but cannot avoid CREATE or DROP (on MySQL).

    May be exec that query using ReadOnly account can solve the problem with no risks/overhead-executions.

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部