pg_send_execute
(PHP 5 >= 5.1.0, PHP 7)
pg_send_execute - 发送一个请求来执行一个给定参数的预处理语句,而不用等待结果。
描述
bool pg_send_execute ( resource $connection , string $stmtname , array $params )
发送一个请求来执行一个给定参数的预处理语句,而不用等待结果。
这与pg_send_query_params()类似,但要执行的命令是通过命名预先准备的语句来指定的,而不是提供查询字符串。该函数的参数与pg_execute()的处理方式相同。像pg_execute()一样,它在7.4以前版本的PostgreSQL上不起作用。
参数
connection
PostgreSQL数据库连接资源。如果connection
不存在,则使用默认连接。默认连接是pg_connect()或pg_pconnect()所做的最后一个连接。
stmtname
准备执行的语句的名称。如果指定了“”,那么执行未命名的语句。该名称必须先使用pg_prepare(),pg_send_prepare()或PREPARE SQL命令进行准备。
params
用于替换原始准备的查询字符串中的$ 1,$ 2等占位符的参数值数组。数组中元素的数量必须与占位符的数量相匹配。
返回值
成功时返回TRUE
成功时失败时返回FALSE
。使用pg_get_result()来确定查询结果。
例子
Example#1使用pg_send_execute()
<?php
??$dbconn?=?pg_connect("dbname=publisher")?or?die("Could?not?connect");
??//?Prepare?a?query?for?execution
??if?(!pg_connection_busy($dbconn))?{
????pg_send_prepare($dbconn,?"my_query",?'SELECT?*?FROM?shops?WHERE?name?=?$1');
????$res1?=?pg_get_result($dbconn);
??}
??//?Execute?the?prepared?query.??Note?that?it?is?not?necessary?to?escape
??//?the?string?"Joe's?Widgets"?in?any?way
??if?(!pg_connection_busy($dbconn))?{
????pg_send_execute($dbconn,?"my_query",?array("Joe's?Widgets"));
????$res2?=?pg_get_result($dbconn);
??}
??
??//?Execute?the?same?prepared?query,?this?time?with?a?different?parameter
??if?(!pg_connection_busy($dbconn))?{
????pg_send_execute($dbconn,?"my_query",?array("Clothes?Clothes?Clothes"));
????$res3?=?pg_get_result($dbconn);
??}
??
?>
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com