I'm trying to execute this query from PHP but it's not working:
$myQuery = 'SET @t1= 5;
INSERT INTO mvt (id_piece, code_mvt, origine_mvt, type_mvt, article_id_article, code_art, des_art, qte_old, qte_mvt, qte_new, link_piece)
SELECT
p.id_bsr,
CONCAT_WS(\'\',\'MVT/15/12/\',LPAD(@t1 := @t1+1, 3, \'0\')) AS code_mvt,
p.code_bsr,
\'Bon Annulation\',
l.article_id_article,
l.code_art,
l.des_art,
qte_art,
qte,
(qte_art + (qte*1)),
\'index.php?p=DetailsBonSortie&idBsr=167\'
FROM
bon_sortie p, ligne_sortie l, article a
WHERE p.id_bsr = l.bon_sortie_id_sortie
AND a.id_article = l.article_id_article
AND id_bsr = 167;
';
As you can see it's an INSERT query from a SELECT query and a variable @t1.
When I execute this query directly in MySQL DB it works fine, but when I try to execute it from php like this:
$conn = new mysqli('host', 'user', 'password', 'database');
$conn->query($myQuery);
it doesn't work!
What am I missing ?
$conn->query()echo $myQuerybefore running, might be an obvious syntax issue.