本文介绍了PDO与pg_ *功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

他们都有准备好的陈述.pg_ *是libpq的包装器.对吧?

They both have prepared statements.pg_* is a wrapper to libpq. Right?

我喜欢PHP中的PDO,但以后不会更改数据库.我应该使用哪个库?有基准吗?PHP版本:5.4

I like the PDO in PHP, but I'm not going to change the database in the future.Which library should I use?Any benchmark?PHP version: 5.4

推荐答案

PDO提供了一个不错的接口,但是更多的通用性也意味着在处理每个后端的细微特性方面会遇到更多的麻烦.如果您查看 bugtracker ,它有很多未解决的问题,其中有些是很严重的

PDO offers a nice interface but more genericity also means more trouble to deal with subtle idiosyncrasies of each backend. If you look at the bugtracker, it has a number of open issues, and some of them are serious.

这是有关postgresql的轶事证据:PDO的解析器在将standard_conforming_strings设置为ON时遇到麻烦(从PG-9.1开始,这是默认值).使用php-5.3.9的测试用例:

Here's an anecdotal evidence with postgresql: PDO's parser has trouble with standard_conforming_strings set to ON (which is now the default, as of PG-9.1).Test case with php-5.3.9:

$dbh->exec("SET standard_conforming_strings=on");
$p=$dbh->prepare("SELECT 1 WHERE 'ab\' = :foo AND 'cd' = :bar");
$p->execute(array(":foo" => "ab", ":bar" => "cd"));

execute()在PDO层意外失败Database error: SQLSTATE[HY093]: Invalid parameter number: :foo.似乎无法将:foo识别为参数.

The execute() unexpectedly fails at the PDO layer with Database error: SQLSTATE[HY093]: Invalid parameter number: :foo. It seems that it's unable to identify :foo as a parameter.

如果查询在'ab\'=:foo之后停止,没有其他条件,则可以正常工作.或者,如果其他条件不包含字符串,它也可以正常工作.

If the query stops after 'ab\'=:foo, without another condition, then it works fine.Or if the other condition does not include a string, it works fine too.

该问题看起来与问题#55335 类似,已被取消为不是错误,我认为这是错误的.[实际上,我什至亲自破解了PDO来修复它,但是这种方式与其他后端不兼容,因此没有补丁.查询词法分析器是如此通用,令我感到不安.]

The problem looks similar to issue #55335 , that was dismissed as Not a bug, quite wrongly in my opinion.[Actually, I've even hacked PDO myself to fix it, but in a way that is incompatible with other backends, so no patch. I was disconcerted by the query lexical analyzer being so generic.]

另一方面,由于pg_ *更接近libpq,这种问题在一开始就不太可能发生,并且如果确实存在,则更容易解决.

On the other hand, pg_* being closer to libpq, this kind of problem is less likely to happen in the first place, and easier to solve if it does.

因此,我的意思是,PDO并非一切都很好.在内部,它肯定比pg_ *更具挑战性,并且更高的复杂性意味着更多的错误.这些错误已解决吗?基于某些bugtracker条目,不一定.

So my point would be that not everything is nice with PDO. Internally, it's certainly more challenging than pg_*, and more complexity means more bugs. Are these bugs addressed? Based on certain bugtracker entries, not necessarily.

这篇关于PDO与pg_ *功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 02:39