|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2004-04-28 04:49 UTC] jlawson-php at bovine dot net
[2005-03-21 09:23 UTC] chriskl@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Dec 03 23:00:01 2025 UTC |
Description: ------------ Using bound parameters when executing SQL commands should be encouraged, since use of it for all substitutable variables will eliminate most SQL injection types of attacks. Although some of the database providers in PHP already provide ways to prepare/execute queries with substituted parameters, not all of them do. The "pgsql" PHP extension for PostgreSQL does not include any existing way, so I have implemented a new pg_query_params() function that allows you to do this in a single function call. Note that this my new method has chosen not follow the style of providing two separate prepare/execute functions for bound parameter execution. This is because with PostgreSQL it would require the user to use a significantly different SQL query format and assign the prepared query a session-unique name, making it much more cumbersome to use. ie: "PREPARE mystmt(text,int,float8) AS insert into abc values($1,$2,$3)" instead of just "insert into abc values($1,$2,$3)" PostgreSQL requires that parameter binding uses numbered placeholders ($1, $2, $3, etc) instead of just an unlabelled "?", that is common for the other providers (like ODBC). The PQexecParams() pqlib function that I depend on is unfortunately only available in PostgreSQL 7.4, so some autoconf checks will need to be added before integrating my new function into PHP. Reproduce code: --------------- A patch including my new extension function will be attached later. However sample code that uses my function might be: $params = array("joe's place", 22, 123.4); pg_query_params("insert into abc values($1,$2,$3)", $params); Expected result: ---------------- n/a Actual result: -------------- n/a