This is an unprepared query that executes multiple statements in laravel.
IlluminateDatabaseConnection::unprepared
$sql ='
CREATE TEMPORARY TABLE test AS SELECT SUM(11) ;
CREATE TEMPORARY TABLE test_3 AS SELECT SUM(11);
select test.* FROM test ;
DROP TABLE IF EXISTS test, test_3;
';
$result = DB::unprepared($sql);
MySQL general query log
It's just like running it from the MySQL console.
Query CREATE TEMPORARY TABLE test AS SELECT SUM(11) ;
CREATE TEMPORARY TABLE test_3 AS SELECT SUM(11);
select test.* FROM test ;
DROP TABLE IF EXISTS test, test_3
Error exception
You can only detect errors for the first query.
The following example returns $result = true
without error.
$sql ='
CREATE TEMPORARY TABLE test AS SELECT SUM(11) ;
CREATE TEMPORARY TABLE test_3 AS SELECT SUM(11);
select test.* FROM test ;
DROP TABLE IF EXISTS test, test_3;
select error_force_test() from dual;
';
$result = DB::unprepared($sql);
Security risk
Since it is not a prepared query, be careful of sql injection when receiving input values.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…