pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: mark <dvlhntr@gmail.com>
To: pgsql-php@postgresql.org
Subject: pdo emulate prepares not working. still getting parse-bind-execute-deallocate in pg log.
Date: Thu, 25 Aug 2011 21:30:24 -0600
Message-ID: <000401cc63a0$7e3bd7b0$7ab38710$@com> (raw)



Hi all,


I am trying to convince some of our php guys to not use prepared statements.


The reason for this is, first reasons is we are seeing no benefit IMO.
performance wise nearly all of the statements are being prepared, executed
and then deallocated in nearly all cases. The other times it's probably only
run twice so it's still not a win. 

The second reason is I want to be able to use transaction pooling with
pgbouncer. This is the primary driving force. 


So someone mashed up a quick bit of php to start testing a few thing. (more
about checking what error cases look like than anything else)

The problem we found is that even with "PDO::ATTR_EMULATE_PREPARES => true"
I still see it preparing statements when I set log_min_duration to 0. 

I am not a php person but I googled around and I can't seem to figure out
why the below isn't working as expected. Any tips on what are we doing
wrong? What should this look like to disable/emulate prepared statements. I
am expecting that if this were working we wouldn't see
parse,bind,execute,deallocate in the Postgres log. 


Apologies if this is the wrong list for this sort of thing.



-Mark

<?php
try {

	// Can run it in a loop to get timed results over a large number of
executions.
	$tStart = microtime(true);
	for ($i=0;$i<1;$i++) {

		$dbh = new PDO('pgsql:host=localhost;dbname=my_mainline',
'postgres', 'postgres', array(PDO::ATTR_EMULATE_PREPARES => true));

		// replace this with a valid int to test the expected case.
		$rname = 'P1\'Partner';

		// Purposely trying to bind a string to an integer column to
see what happens
		// when using client-side prepare emulation vs not using it.
		$stmt = $dbh->prepare("SELECT * FROM my_reseller WHERE
reseller_id=:rname");
		$stmt->bindParam(':rname', $rname);
		$stmt->execute();

		/* Print out results if you want to see them.
		foreach($stmt->fetch() as $row) {
			print_r($row); print("\n");
		}
		*/

		$dbh = null;
	}
	printf("%17s: %.4f secs for %d iterations, avg: %.6f secs\n"
		, 'date'
		, microtime(true) - $tStart
		, $i
		, (microtime(true) - $tStart)/$i
		);
} catch (PDOException $e) {
    print "Error!: " . $e->getMessage() . "<br/>";
    die();
}
?>





view thread (3+ messages)  latest in thread

Message-ID: <000401cc63a0$7e3bd7b0$7ab38710$@com>
Permalink:  ../000401cc63a0$7e3bd7b0$7ab38710$@com/
Also on:    postgresql.org/message-id/000401cc63a0$7e3bd7b0$7ab38710$@com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-php@postgresql.org
  Cc: dvlhntr@gmail.com
  Subject: Re: pdo emulate prepares not working. still getting parse-bind-execute-deallocate in pg log.
  In-Reply-To: <000401cc63a0$7e3bd7b0$7ab38710$@com>
  References: <000401cc63a0$7e3bd7b0$7ab38710$@com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox