[prev in list] [next in list] [prev in thread] [next in thread] 

List:       postgresql-general
Subject:    [GENERAL] Prepared queries vs Non-prepared
From:       Denis Gasparin <denis () edistar ! com>
Date:       2007-03-28 8:30:00
Message-ID: 460A2788.5010806 () edistar ! com
[Download RAW message or body]

Hi!
I am testing the PHP PDO library versus the old style PHP postgres
functions.

I noted that PDO library declare and prepare every statement. I mean:

$s = $db->query("select * from test where field=1");

is equivalent to

$s = $db->prepare("select * from test where field=?");
$s->execute(array('1'));

I logged the queries sent to the database and i saw that they are the
same (apart obviously the parameter):

PREPARE pdo_pgsql_stmt_b7a71234 AS select * from test where field=1
<BIND>
EXECUTE <unnamed>  [PREPARE:  select * from test where field=1]

PREPARE pdo_pgsql_stmt_b7a713b0 AS select * from test where field=$1
<BIND>
EXECUTE <unnamed>  [PREPARE:  select * from test where field=$1]


Speaking about postgresql performance...
would not it be more efficient executing directly the query in the first
case ($db->query) than
preparing a statement without parameters and then executing it?

Thank you in advance,
Denis


---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
       subscribe-nomail command to majordomo@postgresql.org so that your
       message can get through to the mailing list cleanly
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic