Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP statement synchronous or asynchronous

Good morning, I would like to know if PHP prepare statement is synchronous or asynchronous, for example :

$req1 = "UPDATE ...";
$statement1 = $connection->prepare($req1);
$statement1->execute();

$req2 = "SELECT ...";
$statement2 = $connection->prepare($req2);
$statement2->execute();

So the result of the second request depend on the first, it may cause problems or wrong results, in others words, there's a possibility that the second request execute before the first.

I searched for answers, but i haven't found a clear answer. Thanks you.

like image 861
Wajdi Ben Abdallah Avatar asked Sep 13 '25 20:09

Wajdi Ben Abdallah


1 Answers

Database queries are executed synchronously. But don't take my word for it, check the manual:

PDO: http://php.net/manual/en/pdostatement.execute.php

Since the method result is TRUE on success or FALSE on failure you can deduce it is synchronous.

MySQLi: http://php.net/manual/en/mysqli-stmt.execute.php

Same here. So check the documentation and if the execute() returns something related to the result you know it has to be synchronous.

like image 131
KIKO Software Avatar answered Sep 15 '25 10:09

KIKO Software