note 95408 modified in function.pg-query-params by thiago

From: Date: Mon, 04 Jan 2010 13:21:07 +0000
Subject: note 95408 modified in function.pg-query-params by thiago
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-164604@lists.php.net to get a copy of this message
pg_query and pg_query_params can be combined into a single function. This also removes the need to construct a parameter array for pg_query_params: <?php function my_query($conn, $query) { if(func_num_args() == 2) return pg_query($conn, $query); $args = func_get_args(); $params = array_splice($args, 2); return pg_query_params($conn, $query, $params); } ?> Usage: <?php /* non-parameterized example */ my_query($conn, "SELECT $val1 + $val2"); /* parameterized example */ my_query($conn, "SELECT $1 + $2", $val1, $val2); ?> --was-- pg_query and pg_query_params can be combined into a single function. This also removes the need to construct a parameter array for pg_query_params: function my_query($conn, $query) { if(func_num_args() == 2) return pg_query($conn, $query); $args = func_get_args(); $params = array_splice($args, 2); return pg_query_params($conn, $query, $params); } Usage: /* non-parameterized example */ my_query($conn, "SELECT $val1 + $val2"); /* parameterized example */ my_query($conn, "SELECT $1 + $2", $val1, $val2); http://php.net/manual/en/function.pg-query-params.php

« previous php.notes (#164604) next »