PHP:MySQLi查询在通过CLI运行cronjob时返回false和null错误,但如果通过Web服务器调用脚本则有



这个脚本多年来一直运行良好,在某些情况下仍然运行良好,但我正在尝试验证另一种情况,但它失败了,没有任何错误消息。

我已经挣扎了一整天,现在已经走到了死胡同。

我在3个电子邮件收件箱中使用以下内容-我检查电子邮件,使用主题中的详细信息验证客户,然后在插入针对客户的电子邮件内容之前设置客户对象。

这对于现有的2个邮箱来说一直都很好,但第3个(新邮箱(在$this->mysqli->query($query)处不断失败,返回false。

它正确地提取了电子邮件,正如我通过输出电子邮件主题所看到的那样——它有它,它读过它,它正确地构建了SQL查询。。。它就是执行不成功。。。

//Build the query
$query = "SELECT id, 
parent_id, 
name, 
storeno,
make,
active_advisors,
address,
primary_contact,
primary_phone,
primary_email,
secondary_contact,
secondary_phone,
secondary_email,
daily_email_receipients,
wty_analysis_email_recipients,
created,
expiry,
modified,
modified_by,
active,
customer_type
FROM Customer
WHERE LOWER(name) = LOWER('".addslashes($emailHeader['customername'])."')
AND LOWER(storeno) = LOWER('".$emailHeader['storeno']."')
AND LOWER(make) = LOWER('".$emailHeader['make']."')";
//debug query
print $query;
//Execute the query and validate that it was executed without issue
if( $result = $this->mysqli->query($query) ) {
//Print row count for debugging
print "Select returned ".mysqli_num_rows($result)." matching rows for 'Customer' lookup.";
//Check to see if we got what we expected (an single exact match!)
if (mysqli_num_rows($result)==1) {
//Transfer the result into a usable Object
while ($row = $result->fetch_object()) {
$this->setCustomerInformation($row);
}
}
// If we get 0 then we have no match
// If we get > 1 then we have a problem (and still no match)
else { 
print "Could not match email details to a customer: (".implode(",",$emailHeader).")"; 
return false;
}
}
else { 
print 'Mysqli Query returned false: " ('.serialize($this->mysqli).')';
print mysqli_errno($this->mysqli);
print mysqli_error($this->mysqli);
return false;
}   

输出:

SELECT id, 
parent_id, 
name, 
storeno,
make,
active_advisors,
address,
primary_contact,
primary_phone,
primary_email,
secondary_contact,
secondary_phone,
secondary_email,
daily_email_receipients,
wty_analysis_email_recipients,
created,
expiry,
modified,
modified_by,
active,
customer_type
FROM Customer
WHERE LOWER(name) = LOWER('XXXXXXXX')
AND LOWER(storeno) = LOWER('S01')
AND LOWER(make) = LOWER('FO')
Mysqli Query returned false: " (O:6:"mysqli":19:{s:13:"affected_rows";N;s:11:"client_info";N;s:14:"client_version";N;s:13:"connect_errno";N;s:13:"connect_error";N;s:5:"errno";N;s:5:"error";N;s:10:"error_list";N;s:11:"field_count";N;s:9:"host_info";N;s:4:"info";N;s:9:"insert_id";N;s:11:"server_info";N;s:14:"server_version";N;s:4:"stat";N;s:8:"sqlstate";N;s:16:"protocol_version";N;s:9:"thread_id";N;s:13:"warning_count";N;})

到目前为止我所做的:

  1. 我已经输出$query并在MySQL中运行它,它成功地返回了正确的结果
  2. 我比较了所有3次邮箱检查中的mysqli对象,它们是相同的
  3. 我在每个收件箱中都有一封邮件(前2封=成功(,第3封失败
  4. 我在第三个邮箱中只运行了一封邮件=失败(可能是在重置连接(

我已经没有主意了-要测试,不知道去哪里

错误输出为NULL

额外的测试-这个过程是通过cron作业运行的-我刚刚通过浏览器手动运行了这个过程,它可以工作。。。

  • 浏览器中的PHP版本和cli相同
  • Mysqli对象在Browser和CLI中是相同的
  • mysqli->Query((结果不同:

CLI:

NULL

浏览器:

mysqli_result Object
(
[current_field] => 
[field_count] => 
[lengths] => 
[num_rows] => 
[type] => 
)

刚刚发现,mysqli->stat((

CLI:NULL浏览器:已填充

很明显,MySQLi对象存在问题

在查询数据之前尝试调用mysqli_report(MYSQLI_REPORT_ALL)。它启用或禁用内部报告功能。

php.net上的mysqli_report。

此外,我建议不要混合使用面向对象和过程风格的PHP:MySQLi库。

相关内容

最新更新