pg_send_query_params
(PHP 5 >= 5.1.0, PHP 7)
pg_send_query_params — 在不等待结果的情况下向服务器提交命令和单独的参数。
描述
bool pg_send_query_params ( resource $connection , string $query , array $params )
在不等待结果的情况下提交命令并将参数分开给服务器。
这相当于pg_send_query(),只是查询参数可以与query
字符串分开指定。该函数的参数的处理方式与pg_query_params()相同。像pg_query_params()一样,它在7.4之前的PostgreSQL连接上不起作用,并且它只允许查询字符串中的一个命令。
参数
connection
PostgreSQL数据库连接资源。
query
参数化的SQL语句。只能包含一个语句。(不允许使用以分号分隔的多个语句)。如果使用任何参数,它们被称为$ 1,$ 2等。
params
用于替换原始准备的查询字符串中的$ 1,$ 2等占位符的参数值数组。数组中元素的数量必须与占位符的数量相匹配。
返回值
成功时返回TRUE
或失败时返回FALSE
。
使用pg_get_result()来确定查询结果。
例子
示例#1使用pg_send_query_params()
<?php
??$dbconn?=?pg_connect("dbname=publisher")?or?die("Could?not?connect");
??//?Using?parameters.??Note?that?it?is?not?necessary?to?quote?or?escape
??//?the?parameter.
??pg_send_query_params($dbconn,?'select?count(*)?from?authors?where?city?=?$1',?array('Perth'));
??
??//?Compare?against?basic?pg_send_query?usage
??$str?=?pg_escape_string('Perth');
??pg_send_query($dbconn,?"select?count(*)?from?authors?where?city?=?'${str}'");
?>
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com