georgie
Member
Hello
I would run many "INSERT" queries in a scheduled task, separated by a semi-colon.
I well recover my data, I well create queries (copying-pasting queries generated in DB = OK).
But PHP does not seem to want to execute them.
I tried 2 ways to create my sequence of queries, first this "classical" way (which work for me when I have just one query):
It does not work.
After documenting, it seems this other method is recommended, for multiple queries:
OK the sequence generated is the same and works in DB (with a var_dump).
But I can not execute them in my PHP cron plugin. I tried many syntaxs, playing with this in various form:
No way...
I have seen this PHP doc, I tried, but without success ("if...do...if...while... all with my "$db"):
http://php.net/manual/en/mysqli.multi-query.php
Please can you help me?
I would run many "INSERT" queries in a scheduled task, separated by a semi-colon.
I well recover my data, I well create queries (copying-pasting queries generated in DB = OK).
But PHP does not seem to want to execute them.
I tried 2 ways to create my sequence of queries, first this "classical" way (which work for me when I have just one query):
Code:
$query = "
BEGIN ;
INSERT INTO customer (civility, lastname, firstname, email)
VALUES ('$A_var', '$Another_Var', '$Another_Var', '$Another_Var') ;
INSERT INTO address (id_customer, country)
VALUES (LAST_INSERT_ID(), '$Another_Var') ;
INSERT INTO telephone (id_customer, id_address, code_tel1, tel1)
VALUES ( (SELECT MAX(id_customer) FROM customer) , (SELECT MAX(id_address) from address) , '$Another_Var', '$Another_Var') ;
INSERT INTO customer_organisme (id_customer, id_organisme)
VALUES ( (SELECT MAX(id_customer) FROM customer) , 'A_Value') ;
COMMIT ;
" ;
$db->setQuery($query);
$db->query();
After documenting, it seems this other method is recommended, for multiple queries:
Code:
$query = "BEGIN ; ";
$query .= "INSERT INTO customer (civility, lastname, firstname, email)
VALUES ('$A_var', '$Another_Var', '$Another_Var', '$Another_Var') ; ";
$query .= "INSERT INTO address (id_customer, country)
VALUES (LAST_INSERT_ID(), '$Another_Var') ; ";
$query .= "INSERT INTO telephone (id_customer, id_address, code_tel1, tel1)
VALUES ( (SELECT MAX(id_customer) FROM customer) , (SELECT MAX(id_address) from address) , '$Another_Var', '$Another_Var') ; ";
$query .= "INSERT INTO customer_organisme (id_customer, id_organisme)
VALUES ( (SELECT MAX(id_customer) FROM customer) , 'A_Value') ; ";
$query .= "COMMIT ;";
OK the sequence generated is the same and works in DB (with a var_dump).
But I can not execute them in my PHP cron plugin. I tried many syntaxs, playing with this in various form:
Code:
$db->multi_query($query) ;
$db->query() ;
No way...
I have seen this PHP doc, I tried, but without success ("if...do...if...while... all with my "$db"):
http://php.net/manual/en/mysqli.multi-query.php
Please can you help me?