I have rather complex SQL statemens, which are using variables.
The whole block works fine in MySQL workbench.
However, if I want to execute the same code on PHP side, it does not woek.
mysqli_select_db($conn, "$settings_database");
$sql = "
SET @id := null;
UPDATE incidents.enrichment
SET enrichment.ManualEnricher4State = 1
WHERE ParentTableId = @id := (
SELECT * FROM (
SELECT enr.ParentTableId
FROM incidents.enrichment AS enr
WHERE enr.ManualEnricher1State Is NULL
AND (
enr.ManualEnricher4State Is NULL
OR
enr.ManualEnricher4State = 2
)
LIMIT 1
) as x
);
select @id;
";
$sql = mysqli_query($conn, $sql);
$row = mysqli_fetch_array($sql);
var_dump($row);
Could it for some reason be, that the PHP mysql connector has an issue with variables?
Simple querys work fine...
In this example the result of mysqli_query is simply false...
Thanks for the help - meanwhile I have found the solution:
Executing that stuff in single querys and everything works fine...
$sql = "SET @id := null;";
$sql = mysqli_query($conn, $sql);
$sql = "
UPDATE incidents.enrichment
SET enrichment.ManualEnricher4State = 1
WHERE ParentTableId = @id := (
SELECT * FROM (
SELECT enr.ParentTableId
FROM incidents.enrichment AS enr
WHERE enr.ManualEnricher1State Is NULL
AND (
enr.ManualEnricher4State Is NULL
OR
enr.ManualEnricher4State = 2
)
LIMIT 1
) as x
);
";
$sql = mysqli_query($conn, $sql);
$sql = "select @id;";
$sql = mysqli_query($conn, $sql);