防止在 laravel 查询生成器上对数据库执行插入语句

Prevent to execute insert statements to database on laravel query builder

我有这样的查询生成器方法:

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

我想执行 select 语句而不是 insertupdate 语句

您可以解析 $query 检查不需要的 INSERT/UPDATE/etc。使用 sql 解析器。

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)

来自 sql-parser-in-php.

但正如@AlonEitan 所指出的那样,事务和回滚可以完成这些工作,但无法避免创建或删除(MySQL)。

可能是执行查询使用ReadOnly帐户可以解决没有risks/overhead-executions.

的问题