pg_send_prepare
(PHP 5 >= 5.1.0, PHP 7)
pg_send_prepare - 发送一个请求来创建一个带有给定参数的预处理语句,而不用等待完成。
描述
bool pg_send_prepare ( resource $connection , string $stmtname , string $query )
发送请求以创建具有给定参数的预准备语句,而无需等待完成。
这是pg_prepare()的一个异步版本:它返回TRUE
它是否能够分派请求,FALSE
如果没有。调用成功后,调用pg_get_result()来确定服务器是否成功创建了预准备语句。该函数的参数的处理方式与pg_prepare()相同。像pg_prepare()一样,它在7.4以前的PostgreSQL版本上不起作用。
参数
connection
PostgreSQL数据库连接资源。如果connection
不存在,则使用默认连接。默认连接是pg_connect()或pg_pconnect()所做的最后一个连接。
stmtname
提供准备好的声明的名称。必须是每个连接唯一的。如果指定了“”,则创建一个未命名的语句,覆盖任何先前定义的未命名的语句。
query
参数化的SQL语句。只能包含一个语句。(不允许使用以分号分隔的多个语句)。如果使用任何参数,它们被称为$ 1,$ 2等。
返回值
成功时返回TRUE
成功失败时返回FALSE
。使用pg_get_result()来确定查询结果。
例子
例#1使用pg_send_prepare()
<?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