Page 1 of 1

PDO PostgreSQL cannot insert multiple commands into a pre...

Posted: Fri Mar 05, 2010 8:45 am
by alexeyfressko
I developed application on Windows/Apache/PHP 5.2/PostgreSQL 8.3. It is all working.
I moved my application to hosting CentOS/Apache/PHP 5.2/PostgreSQL 8.3 and get error with PDO PostgreSQL.

Statements like

Code: Select all

update table set value=1 where id=1;
update table set value=2 where id=2;
generate error: cannot insert multiple commands into a prepared statement

This error occups when I try to prepare command:

Code: Select all

$connection = new PDO('pgsql:host=localhost;dbname=databases', $user, $password);
$statement = $connection->prepare('update table set value=1 where id=1;update table set value=2 where id=2');
$result = $statement->execute($params); 
Has everyone has this error?
On my machine I have libpq version 8.2.3, but on hosting 8.1.11. Is this important?

Thanks for help.

Re: PDO PostgreSQL cannot insert multiple commands into a pre...

Posted: Fri Mar 05, 2010 9:08 am
by Weirdan
The documentation for PQprepare (underlying library function) explicitly forbids multiple statements in a single prepare call:
The function creates a prepared statement named stmtName from the query string, which must contain a single SQL command.
Probably it was working on your installation by virtue of client-side prepares.

Re: PDO PostgreSQL cannot insert multiple commands into a pre...

Posted: Fri Mar 05, 2010 9:30 am
by alexeyfressko
Weirdan wrote:Probably it was working on your installation by virtue of client-side prepares.
So what option or param in PDO can I change to turn it on?

Re: PDO PostgreSQL cannot insert multiple commands into a pre...

Posted: Fri Mar 05, 2010 9:46 am
by Weirdan
pass array(PDO::ATTR_EMULATE_PREPARES => true) as fourth parameter to PDO constructor.

Re: PDO PostgreSQL cannot insert multiple commands into a pre...

Posted: Fri Mar 05, 2010 10:17 am
by alexeyfressko
It is not working. Still have this error on hosting.