我正在处理的项目中有遗留代码。
它看起来像这样(为便于阅读而简化了一点):
$sql = "SELECT something
FROM table
WHERE something = 'something'";
$st = $this->dbPdo->prepare($sql);
$st->execute();
if ($rows = $st->fetchAll(\PDO::FETCH_ASSOC)) {
// Some code that wasn't executing for some reason on
// production, but was working on live
}
在我的本地项目副本上,此代码有效。但是在生产上没有。 当我将其更改为调试$ rows中的内容时,它开始工作。
$sql = "SELECT something
FROM table
WHERE something = 'something'";
$st = $this->dbPdo->prepare($sql);
$st->execute();
$rows = $st->fetchAll(\PDO::FETCH_ASSOC); // rows is array with 15 elements
error_log( 'rows: ' . json_encode($rows) );
if ($rows) {
// Now this code is working
}
有人可以解释我为什么吗?没有其他任何改变。