PHP:MySQLi查询在通过CLI运行cronjob时返回false和null错误,但在通过Web服务器调用脚本时有效
这个脚本多年来一直运行良好,在某些情况下仍然运行良好,但我正在尝试验证另一种情况,但它失败了,没有任何错误消息 我已经为此奋斗了一整天,现在已经走到了死胡同 我在3个电子邮件收件箱中使用以下内容-我检查电子邮件,使用主题中的详细信息验证客户,然后在针对客户插入电子邮件内容之前设置客户对象 对于现有的2个邮箱来说,这已经并且仍然可以正常工作,但是第3个邮箱(新邮箱)在PHP:MySQLi查询在通过CLI运行cronjob时返回false和null错误,但在通过Web服务器调用脚本时有效,php,mysqli,cron,Php,Mysqli,Cron,这个脚本多年来一直运行良好,在某些情况下仍然运行良好,但我正在尝试验证另一种情况,但它失败了,没有任何错误消息 我已经为此奋斗了一整天,现在已经走到了死胡同 我在3个电子邮件收件箱中使用以下内容-我检查电子邮件,使用主题中的详细信息验证客户,然后在针对客户插入电子邮件内容之前设置客户对象 对于现有的2个邮箱来说,这已经并且仍然可以正常工作,但是第3个邮箱(新邮箱)在$This->mysqli->query($query)返回false时一直失败 正如我通过输出电子邮件主题所看到的那样,它正确地提
$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;})
到目前为止我所做的:
- 浏览器和cli中的PHP版本相同
- Mysqli对象在浏览器和CLI中是相同的
- mysqli->Query()结果不同:
mysqli_result Object
(
[current_field] =>
[field_count] =>
[lengths] =>
[num_rows] =>
[type] =>
)
刚刚发现,mysqli->stat()
CLI:NULL
浏览器:已填充
显然,MySQLi对象存在问题在查询数据之前,请尝试调用
MySQLi\u report(MySQLi\u report\u ALL)
。它启用或禁用内部报告功能
另外,我建议不要将面向对象和过程风格的库混合使用。您已经确定问题在于运行SQL查询,但您的问题不包括查询、错误号或错误消息?你能在你的问题中包含这些信息吗?你确定它从实际邮箱中提取了你期望的数据,上面的
1
是给定的,如果查询运行了3次调用中的2次,那么查询显然不是问题,但你是在准备SQL,还是只是在向其中注入数据。如果你有诸如引号之类的问题,你可以得到各种各样的问题,这些问题没有被转义,而不看你是如何把查询放在一起的。人们所能做的就是猜测,因为这不是一个可测试的问题。如果查询没有问题,那么它一定是数据…另一个例子$emailHeader['make']=“thing's”
这个单引号将终止您的SQL查询。akaLOWER(make)=LOWER('thing's')
我添加了$query-它没有准备好,只是一个普通的SQL查询。我绝对肯定它正在从实际的邮箱中提取正确的数据-我们已经测试和验证了一整天。我正在使用print$query-然后将其复制并直接粘贴到MySQL中,得到预期结果…@php-b-grader-如果查询正常,query()
不会返回false
。MySQL错误是什么?
mysqli_result Object
(
[current_field] =>
[field_count] =>
[lengths] =>
[num_rows] =>
[type] =>
)