普通网友 2018-02-18 12: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 12: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.

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

报告相同问题?

悬赏问题

  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图