Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id E7EB29FA65C for ; Mon, 5 Feb 2007 22:20:56 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-new, port 10024) with ESMTP id 27431-05 for ; Mon, 5 Feb 2007 22:20:48 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from floppy.pyrenet.fr (floppy.pyrenet.fr [194.116.145.2]) by postgresql.org (Postfix) with ESMTP id 6B8349FA371 for ; Mon, 5 Feb 2007 22:20:53 -0400 (AST) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id EB32130AF0; Tue, 6 Feb 2007 03:20:51 +0100 (MET) From: ljb X-Newsgroups: pgsql.interfaces.php Subject: Re: pg_[un]escape_bytea, pgsql 8.2.1, php 5.1.6, Linux Date: Tue, 6 Feb 2007 02:20:51 +0000 (UTC) Organization: Hub.Org Networking Services Lines: 22 Message-ID: References: <302670f20702011827x28d9a689m388b2c8a703f31af@mail.gmail.com> <302670f20702022009x417a210fm5e0fa36d860a225@mail.gmail.com> <200702051101.40315.vdephily@bluemetrix.com> X-Complaints-To: usenet@news.hub.org User-Agent: slrn/0.9.8.1 (Linux) To: pgsql-php@postgresql.org X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200702/10 X-Sequence-Number: 3693 vdephily@bluemetrix.com wrote: >... > I think you can instead use prepared statements via SQL directly (as php > probably does in the end) : > > // initialisation > pg_query('PREPARE mystatement (bytea) AS INSERT INTO mytable (bd) VALUES > ($1);'); > // insert loop > pg_query("EXECUTE mystatement (' . pg_escape_bytea($data) . "');"); > > Annoying to have to do all this yourself, but it should work (and it *is* a > parameterized query). It's sort of a parameterized query, but not really in the sense the original poster wants. That is, it does not protect against SQL injection attacks the way a true parameterized query does (with the variable data passed outside of the SQL statement itself, and not subject to SQL parsing). If some way around pg_escape_bytea were to be found (as perhaps happened before with multi-byte characters and PQescapeString), the above could be vulnerable. In fact I don't see where it is any safer than just doing pg_query("INSERT ... '" . pg_escape_bytea($data) . "')");