【发布时间】:2014-03-09 16:38:18
【问题描述】:
我已经把它剥离了,试图找到这个问题的根源,但根本无法确定它。
这成功地回显了每个 ID
$result = mysqli_query($con,"SELECT id FROM users");
// Each user matching criteria
while($row = mysqli_fetch_array($result))
{
echo $row['id'];
}
但是,当我包含 Mandrill 时,它会停止工作,但是我仍然会得到第一个 ID 回显
// 搜索昨天注册的用户的数据库 $result = mysqli_query($con,"SELECT id FROM users");
// Each user matching criteria
while($row = mysqli_fetch_array($result))
{
echo $row['id'];
include($_SERVER['DOCUMENT_ROOT'].'/src/Mandrill.php');
$mandrill = new Mandrill('hidden');
try {
$template_name = $content_template;
$message = array(
'html' => '<p>Example HTML content</p>',
'text' => 'Example text content',
'subject' => 'test',
'from_email' => 'hidden',
'from_name' => 'hidden',
'to' => array(
array(
'email' => 'hidden',
'name' => 'Tim',
'type' => 'to'
)
),
'headers' => array('Reply-To' => 'hidden.com'),
'important' => false,
'track_opens' => true,
'track_clicks' => true,
'tags' => array('$meta_tags'),
'google_analytics_domains' => array('hidden'),
'metadata' => array('website' => 'hidden')
);
$ip_pool = 'Main Pool';
$result = $mandrill->messages->sendTemplate('jotText-Auto-i101-welcome', $template_content, $message, $async, $ip_pool, $send_at);
print_r($result);
} catch(Mandrill_Error $e) {
// Mandrill errors are thrown as exceptions
echo 'A mandrill error occurred: ' . get_class($e) . ' - ' . $e->getMessage();
// A mandrill error occurred: Mandrill_Unknown_Subaccount - No subaccount exists with the id 'customer-123'
throw $e;
}
}
我得到的错误信息是
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, array given in /home/timbaker/public_html/jottext/foundation/database_tasks/cron_welcome.php on line 18
这对我来说是原始查询的问题......但我无法弄清楚为什么 Mandrill 会导致这种情况发生?
另外值得注意的是: - 没有来自 Mandril 的错误消息 - 电子邮件确实发送成功
【问题讨论】:
-
您应该将 include 和 $mandrill = new Mandrill 添加到循环之外,这样您就没有在循环的每次迭代中包含文件和实例化新对象的开销