#48764 [NEW]: PDO_pgsql::query always uses implicit prepared statements if v3 proto available

[email protected] ("mark dot kirkwood at catalyst dot net dot nz")
Newsgroups php.bugs
Message-ID <[email protected]>
From:             mark dot kirkwood at catalyst dot net dot nz
Operating system: Linux 2.6.28 (Ubuntu) amd64
PHP version:      5.3CVS-2009-07-01 (snap)
PHP Bug Type:     PDO related
Bug description:  PDO_pgsql::query always uses implicit prepared statements if v3 proto available

Description:
------------
If the libpq v3 protocol is available, the PDO_pgsql::query will use
implicit prepared statements. This can be a big performance hit for apps
that execute a lot of small sql statements. It would be good to be able to
switch this feature off as required.

Example code snippet to illustrate the use case is below:

Looking at the php code, it seems that either of 

PDO::ATTR_EMULATE_PREPARES 
PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT

should be able to do this. However neither actually have any effect in
this case.

I have a patch that makes the latter work in this case.

Reproduce code:
---------------
//Example code snippet
// (now while this cries out to be converted to use $dbh->prepare and
// $stmt->execute(), more complex cases may not just reexecute
// the same or similar sql)
//
$dbh = new PDO($url, $user);
$dbh->beginTransaction();

for ($i = 0; $i < $num_execs; $i++) {
  $stmt = $dbh->query($sql);
}

//Adding these directives has no effect:
//
$dbh = new PDO($url, $user, "", array(PDO::ATTR_EMULATE_PREPARES =>
true));
//
//or
//
$dbh->setAttribute(PDO::PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT,
true);


Expected result:
----------------
Setting PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT or maybe
ATTR_EMULATE_PREPARES should stop server side prepare in PDO::query

Actual result:
--------------
Server side prepare is always used if libpq v3 protocol is detected.

-- 
Edit bug report at http://bugs.php.net/?id=48764&edit=1
-- 
Try a CVS snapshot (PHP 5.2):        http://bugs.php.net/fix.php?id=48764&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):        http://bugs.php.net/fix.php?id=48764&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):        http://bugs.php.net/fix.php?id=48764&r=trysnapshot60
Fixed in CVS:                        http://bugs.php.net/fix.php?id=48764&r=fixedcvs
Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=48764&r=needdocs
Fixed in release:                    http://bugs.php.net/fix.php?id=48764&r=alreadyfixed
Need backtrace:                      http://bugs.php.net/fix.php?id=48764&r=needtrace
Need Reproduce Script:               http://bugs.php.net/fix.php?id=48764&r=needscript
Try newer version:                   http://bugs.php.net/fix.php?id=48764&r=oldversion
Not developer issue:                 http://bugs.php.net/fix.php?id=48764&r=support
Expected behavior:                   http://bugs.php.net/fix.php?id=48764&r=notwrong
Not enough info:                     http://bugs.php.net/fix.php?id=48764&r=notenoughinfo
Submitted twice:                     http://bugs.php.net/fix.php?id=48764&r=submittedtwice
register_globals:                    http://bugs.php.net/fix.php?id=48764&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=48764&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=48764&r=dst
IIS Stability:                       http://bugs.php.net/fix.php?id=48764&r=isapi
Install GNU Sed:                     http://bugs.php.net/fix.php?id=48764&r=gnused
Floating point limitations:          http://bugs.php.net/fix.php?id=48764&r=float
No Zend Extensions:                  http://bugs.php.net/fix.php?id=48764&r=nozend
MySQL Configuration Error:           http://bugs.php.net/fix.php?id=48764&r=mysqlcfg
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.