Skip to content

Commit 6feb33f

Browse files
committed
Merge branch 'driesvints-patch-1' into 8.x
2 parents 1291ab1 + acae152 commit 6feb33f

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

database.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,24 @@ Some database statements do not return any value. For these types of operations,
179179

180180
DB::statement('drop table users');
181181

182+
<a name="running-an-unprepared-statement"></a>
183+
#### Running An Unprepared Statement
184+
185+
Sometimes you may want to execute an SQL statement without binding any values. You may use the `DB` facade's `unprepared` method to accomplish this:
186+
187+
DB::unprepared('update users set votes = 100 where name = "Dries"');
188+
189+
> {note} Since unprepared statements do not bind parameters, they may be vulnerable to SQL injection. You should never allow user controlled values within an unprepared statement.
190+
191+
<a name="implicit-commits-in-transactions"></a>
192+
#### Implicit Commits
193+
194+
When using the `DB` facade's `statement` and `unprepared` methods within transactions you must be careful to avoid statements that cause [implicit commits](https://dev.mysql.com/doc/refman/8.0/en/implicit-commit.html). These statements will cause the database engine to indirectly commit the entire transaction, leaving Laravel unaware of the database's transaction level. An example of such a statement is creating a database table:
195+
196+
DB::unprepared('create table a (col varchar(1) null)');
197+
198+
Please refer to the MySQL manual for [a list of all statements](https://dev.mysql.com/doc/refman/8.0/en/implicit-commit.html) that trigger implicit commits.
199+
182200
<a name="listening-for-query-events"></a>
183201
## Listening For Query Events
184202

0 commit comments

Comments
 (0)