因此,我正在创建一个 cronJob,它将从我的用户表中选择所有用户,然后将用户全名存储在变量中。所有这些都发生在 while 循环内,在同一个循环内,我从 customerLeads 表中选择所有内容,其中 signedTo
列等于用户全名。然后在这个循环中,我想记录 customerName 并将它们全部存储在一个数组中。因此每个用户都会有自己的数组,其中包含所有的customersNames。
这样做的目的是每天早上运行它,这样如果用户在超过 2 天内没有更新 customerLead,他们就会收到一封电子邮件。
但是我不断收到此错误;
Fatal error: Uncaught Error: Call to a member function fetch() on boolean in /.../customerLeadReminder.php:18 Stack trace: #0 {main} thrown in /homepages/.../customerLeadReminder.php on line 18
我上网查了一下,一切都说是连接不工作,但我检查了一下,连接运行正常...
问题:为什么会出现此错误以及我做错了什么?
<?php
//Error Reporting
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
error_reporting(-1);
require '../includes/conn.php';
$userList = $salesConn->query("SELECT `email`, `firstname`, `lastname` FROM `users`");
while ($uRow = $userList->fetch()) {
$user_name = $uRow['firstname']." ".$uRow['lastname'];
print_r($uRow);
$customerList = $salesConn->query("SELECT * FROM `customerLeads` WHERE curdate() >= (dateUpdated + interval 2 day) AND `assisgnedTo` = '$user_name' ORDER BY `customerID` DESC");
// show this on error
if (!$customerList) {
// For PDO:
echo $salesConn->errorInfo();
}
while ($cRow = $customerList->fetch()) {
$leadID = $cRow['customerID'];
$firstName = $cRow['customerFirstName'];
$lastName = $cRow['customerLastName'];
$tele = $cRow['customerTel'];
....
$dateCreated = $cRow['dateCreated'];
$dateUpdated = $cRow['dateUpdated'];
}
}
?>
通过打印 $uRow
显示:
Array ( [email] => joe.blogs@outlook.com [0] => joe.blogs@outlook.com [firstname] => Joe [1] => Blogs [lastname] => Blogs [2] => Blogs )
连接页面是:
<?php
$salesConn = new PDO('mysql:host=HOST;dbname=DBNAME', 'USERNAME', 'PASSWORD');
$salesConn->setAttribute(PDO::ATTR_ERRMODE);
?>
新错误:警告:PDO::setAttribute() 需要 2 个参数,其中 1 个在/homepages/38/d735513801/htdocs/includes/conn.php 第 8 行中给出
最佳答案
SELECT * FROM `customerLeads` WHERE curdate() >= (dateUpdated + interval 2 day) AND `assisgnedTo` = '$user_name' ORDER BY `customerID` DESC
您使用了两次 WHERE 子句。你的 mysql 中有语法错误。当您想要比较数字计算的结果时,最好在查询中使用括号。
关于PHP 多个数据库连接失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54554773/