我有相当复杂的SQL状态,它们正在使用变量。
整个块在MySQL工作台中运行良好。
但是,如果我想在PHP端执行相同的代码,那么它就不会瞎眼了。
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);
可能由于某种原因,PHP mysql连接器存在变量问题吗?
简单的查询工作正常......
在这个例子中,mysqli_query的结果只是假......
感谢您的帮助 - 同时我找到了解决方案:
在单个查询中执行那些东西,一切正常......
$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);