php mysql query file .sql async, I wish it was sync

116 Views Asked by At

php5.6, Zend Framework 2, mysql 5.7, PDO driver

My goal is to execute sync a .sql file with various sql statements, including 3500 sql insert statements, from php Zend2 app connected to mysql via PDO

file script.sql

USE `blugw_refactoring`;

/* table command_queue_commands_archive  */

TRUNCATE `my_table1`;

insert into `my_table1` CLOLUMNS (VALUES);
insert into `my_table1` CLOLUMNS (VALUES);
insert into `my_table1` CLOLUMNS (VALUES);
. . .
3500 rows
. . .

update `my_table2` set ...;
update `my_table2` set ...;
update `my_table2` set ...;

update `my_table3` set ...;
update `my_table3` set ...;
update `my_table3` set ...;

I can't call mysql client directly from PHP because the application is on docker container, I have to go through my php / pdo connection to invoke mysql.

I found a way to execute the contents of the .sql file with the following instructions:

$db = $ adapter = new Zend\Db\Adapter\Adapter($config_PDO);
$sql = file_get_contents ($file_sql1);
// ??? how to query sync ???
$res = $ db->query ($sql);

Unfortunately the query is executed asynchronously, that is, the focus is returned to PHP before the insert operation is completed

a sleep() istruction works , but isn t a good solution

I think there might also be some MYSQL directive to put in the script.sql file which might make the execution synchronous,

please do you know some pdo options, or mysql directive, to make execution synchronized? thanks for the replies from now

0

There are 0 best solutions below