From: Chris <dmagick@gmail.com>
To: V S P <toreason@fastmail.fm>
Cc: pgsql-php@postgresql.org
Subject: Re: [Q] PDO use to bind arrays for insert
Date: Mon, 17 Nov 2008 08:41:57 +1100
Message-ID: <492093A5.7040606@gmail.com> (raw)
In-Reply-To: <1226803530.24888.1284994985@webmail.messagingengine.com>
References: <1226803530.24888.1284994985@webmail.messagingengine.com>
V S P wrote:
> Hi,
> I appologize in advance, if this is not the right place
> to ask (but I would appreciate then a pointer where I could ask)
>
> I am using PHP 5.2.6 and Postgres 8.3 both on windows right now.
>
> Wanted to know if there is a way to pass via PDO (because
> that's how I connect now to Postgres)
>
> an array of values to insert at once
>
> for example:
>
> I have a PHP class:
>
> cwork
> $work_id;
> $work_desc;
>
>
> I have, say, an array of 50 objects of type cwork
>
> arr_work
>
> I would like to insert all items in the array at once
> so that I would do one trip to the database.
PDO doesn't let you send multiple queries in the one request.
Since you're connecting to postgres, you can use this to do a bulk-insert:
http://www.php.net/manual/en/function.pg-put-line.php
Though it's not part of pdo, and also postgres 'copy from stdin' is all
or nothing - so if you have one line of bad data in there, none of it's
committed.
--
Postgresql & php tutorials
http://www.designmagick.com/
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: dmagick@gmail.com, toreason@fastmail.fm
Subject: Re: [Q] PDO use to bind arrays for insert
In-Reply-To: <492093A5.7040606@gmail.com>
References: <1226803530.24888.1284994985@webmail.messagingengine.com> <492093A5.7040606@gmail.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