普通网友 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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?