我有一个函数应该从数据库中获取一些 API 令牌。测试了脚本后,我发现准备 SQL 语句的行正在杀死脚本:
static function get_tokens($platform, $is_breaking_news = 0, $in_test_mode=0) // 1-android, 2-ios
{
global $dbh;
$paid =2;
$status = 1;
$result = array();
$query = '
SELECT
mobile_install_device_token, mobile_install_id
FROM
' . TABLE_PREFIX . 'mobile_installs
WHERE
mobile_install_platform = :platform
AND
mobile_install_app_type = :paid
AND ';
if ($is_breaking_news)
{
$query .= '
mobile_install_pn_status > :status
';
$status = 0;
}
else
{
$query .= '
mobile_install_pn_status = :status
';
}
$stmt = $dbh->prepare($query); // **THIS IS THE KILLER!**
try
{
$stmt->bindParam(':platform', $platform);
$stmt->bindParam(':paid', $paid);
$stmt->bindParam(':status', $status);
$stmt->execute();
}
catch(PDOException $e)
{
Utils::sql_fail($query, $e->getMessage());
}
while($row = $stmt->fetch())
{
if ($in_test_mode)
{
if (!in_array($row['mobile_install_id'], array(4, 5, 13, 8)))
{
continue;
}
}
echo 'send to ' . $row['mobile_install_id'] . PHP_EOL;
$result[] = $row['mobile_install_device_token'];
}
return $result;
}//end function get_tokens
我发现这是一个已知的错误,但那里提供的解决方案似乎不起作用。有任何想法吗?