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

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
alexeyfressko
Forum Newbie
Posts: 3
Joined: Fri Mar 05, 2010 8:27 am

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

Post 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.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

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

Post 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.
alexeyfressko
Forum Newbie
Posts: 3
Joined: Fri Mar 05, 2010 8:27 am

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

Post 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?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

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

Post by Weirdan »

pass array(PDO::ATTR_EMULATE_PREPARES => true) as fourth parameter to PDO constructor.
alexeyfressko
Forum Newbie
Posts: 3
Joined: Fri Mar 05, 2010 8:27 am

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

Post by alexeyfressko »

It is not working. Still have this error on hosting.
Post Reply