尝试使用pg_query_params()的Apache SSL错误

时间:2015-09-18 22:39:30

标签: php postgresql ssl

在尝试使用PHP 5.3.29中的pg_query_params()向远程PostgreSQL 9.3数据库发出请求时,我有时会遇到一个模糊的错误:

<br /> <b>Warning</b>: pg_query_params() [<a href='function.pg-query-params'>function.pg-query-params</a>]: Query failed: SSL error: block type is not 01 in <b>/index.php</b> on line <b>171</b><br />

它只是间歇性地发生 - 查询通常会成功 - 所以我知道它不是我的代码的语法或其他问题。但是,为了完整起见,这里是相关的PHP和SQL:

...
$query = <<<POWER_TEACHERS
WITH teachers AS (
    SELECT ca.started_by_id, sus.email, sus.zip_code
    FROM   common_activityinstance ca, socrative_users_socrativeuser sus
    WHERE  ca.end_time >= $1::date
    AND    ca.end_time <  $2::date + 1
    AND    ca.started_by_id = sus.id
    AND    sus.zip_code IS NOT NULL
    GROUP BY ca.started_by_id, sus.email, sus.zip_code
    HAVING COUNT(*) >= 3
    ORDER BY random()
    LIMIT 250
), activities AS (
    SELECT ca.id, t.email, t.zip_code
    FROM   common_activityinstance ca, teachers t
    WHERE  ca.end_time >= $1::date
    AND    ca.end_time <  $2::date + 1
    AND    ca.started_by_id = t.started_by_id
)
SELECT zip_code, email
FROM (
    SELECT DISTINCT ON (s.user_uuid) s.user_uuid, a.id, a.email, a.zip_code
    FROM   students_studentresponse s, activities a
    WHERE  s.activity_instance_id = a.id
    ORDER BY s.user_uuid
) sub
GROUP BY email, zip_code
HAVING COUNT(*) >= 3
ORDER BY zip_code;
POWER_TEACHERS;
$result = pg_query_params($con, $query, array($lastWeek, $today)); // error here
...

可能导致这种奇怪行为的原因是什么?

1 个答案:

答案 0 :(得分:0)

如果这有助于其他任何人,我通过放弃PHP,切换到Node.js并使用优秀的pg-native模块“解决”了这个问题。我从上面的查询完全没有变化,执行没有任何问题。