Using Laravel's query builder, I formed a database transaction with the following queries:
DB::transaction(function($map) {
DB::connection('network')->table('Maps')
->insert([
'Name' => '?',
'Gametype' => '?',
'Author' => '?',
'Enabled' => '?',
'Public' => '?',
'Required' => '?',
'Image' => '?',
'ReleaseDate' => '?',
'ContactInfo' => '?',
], [
$map['name'],
$map['game'],
$map['creator'],
$map['enabled'],
$map['public'],
$map['required'],
$map['image-url'],
$map['released'],
$map['contact'],
]);
DB::connection('website')->table('panel_logs')
->insert([
'message' => 'Added a new map to '. $map['game'] .' called '. $map['name'] .'.',
'timestamp' => Carbon::now(),
'tag' => 2,
'username' => Auth::user()->username
]);
});
The first query inserts data into a database using query bindings. I have an array called maps
containing the data for the insert and I would like to bind on the values however it's not working because it's treating the second array as another insert. In the docs, they didn't provide an example of query binding using the builder. Would it be better just to insert the data without binding? Will this still protect me from SQL injection as I think Laravel uses prepared statements anyway with their builder. I just would like to make sure things don't go horribly wrong.