[英]How to execute different queries same time in Laravel
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('i.babirli@outlook.csosm');";
$query2 = "insert into users(`name`,`email`,`password`) values('Ismat','i.babirlis@outlook.com','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.
谢谢你的回答。
You can do multiple insert using DB::unprepared() but can not get result of select query.您可以使用 DB::unprepared() 进行多次插入,但无法获得选择查询的结果。 As in the definition of this function it call PHP PDO
在这个函数的定义中,它调用 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.和 PHP doc ,明确声明它只会返回 true 或 false 并建议使用 query for select 语句。
So, what you can do here is, execute multiple insert into single command and for select use query function or eloquent.所以,你在这里可以做的是,将多个插入到单个命令中,并为选择使用查询功能或雄辩。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.