Reputation: 69
I want to insert data to different tables and select some data form table in one connection. Look like:
DB::connection()->enableQueryLog();
$query1 = "insert into emails(`email`) values('[email protected]');";
$query2 = "insert into users(`name`,`email`,`password`) values('Ismat','[email protected]','123456');";
$query3 = "select name from users where id=1;";
DB::unprepared( $query1.$query2.$query3);
$queries = DB::getQueryLog();
But there is unprepared method, which doesn't return me selected data. Have any way for this? Thank you for answering.
Upvotes: 2
Views: 1533
Reputation: 494
You can do multiple insert using DB::unprepared() but can not get result of select query. As in the definition of this function it call PHP PDO
$this->getPdo()->exec($query)
And PHP doc, clearly state that it will only return true or false and suggest to use query for select statement.
So, what you can do here is, execute multiple insert into single command and for select use query function or eloquent.
Upvotes: 2