PDO如何不返回pg_query()做的行? [英] How can PDO not return a row which pg_query() does?

查看:81
本文介绍了PDO如何不返回pg_query()做的行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张表,上面有一个大字串PK,一个字符改变FK和bigint FK,并在这些FK上有唯一的约束,一个字符改变NOT NULL和两个可为null的smallint.

I had a table with a bigserial PK, one character varying FK and a bigint FK and a unique constraint on these FKs, a character varying NOT NULL and two nullable smallints.

所有这些都在具有Ubuntu 14.04.2 LTS,PHP 5.5.9和PostgreSQL 9.3以及发行版中所有其他软件包的VM中运行.

All of this was running in a VM with Ubuntu 14.04.2 LTS, PHP 5.5.9 and PostgreSQL 9.3 and all other packages from the distribution.

我做到了

$pdo->query("SELECT * FROM table")->fetchAll(PDO::FETCH_ASSOC)

$r = pg_query($db, "SELECT * FROM table");
pg_fetch_all($r)

后者返回所有行,而前者返回除一行之外的所有行.

The latter returned all rows while the former returned all rows except for one.

我也尝试选择该行,并且pg_*()函数按预期工作时,PDO没有返回任何行.

I tried to select that very row as well, and while the pg_*() functions worked as expected, PDO did not return any row.

更奇怪的是,这种差异仅在带有lighttpd 1.4.33的PHP-FPM中出现,而在shell中与PHP CLI一起运行时则没有出现.

To make it even stranger, the discrepancy only emerged in PHP-FPM with lighttpd 1.4.33, but not when run with PHP CLI in a shell.

那怎么可能? 还有其他人遇到过类似情况吗? 而且我如何确定PDO不会再让我失望?

How can that be? Did anyone else encounter a similar situation? And how can I be sure that PDO will not fail me again?

我什至尝试重新启动VM并重新启动PostgreSQL,但是结果没有改变.

I even tried rebooting the VM and restarted PostgreSQL, but the results did not change.

可悲的是,我没有这个东西的备份,因为我必须尽快使它工作,所以我删除了那个神秘的行,并用一个新的行代替了它,除了PK以外,所有列都相同.

Sadly, I do not have a backup of this stuff because I had to get things working ASAP, so I deleted that mysterious row and replaced it with a new one, identical in all columns except for the PK.

双方都正确返回了新行.

The new row was returned properly by both.

推荐答案

事实证明,当PostgreSQL的索引损坏时,PostgreSQL可能会产生令人困惑且不一致的结果.

Turns out, PostgreSQL may yield confusing and inconsistent results when its index gets corrupted.

在这种情况下,只需重新创建索引并检查它是否可以解决您的问题.

In this case, just recreate the index and check if it fixes your problem.

这篇关于PDO如何不返回pg_query()做的行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆