pg_get_notify
(PHP 4 >= 4.3.0, PHP 5, PHP 7)
pg_get_notify - 获取SQL NOTIFY信息
描述
array pg_get_notify ( resource $connection [, int $result_type ] )
pg_get_notify()获取由NOTIFY SQL命令生成的通知。要接收通知,必须发出LISTEN SQL命令。
参数
connection
PostgreSQL数据库连接资源。
result_type
这是一个用于控制返回数组的索引方式可选参数。result_type
是一个常量,可以为以下值:PGSQL_ASSOC
,PGSQL_NUM
和PGSQL_BOTH
。使用PGSQL_NUM
,pg_get_notify()将返回数字索引的阵列,使用PGSQL_ASSOC
它会返回仅关联索引而PGSQL_BOTH
,默认值,将返回数字及关联索引。
返回值
包含NOTIFY 消息名称和后端PID 的数组。从PHP 5.4.0版本开始,如果服务器支持,该阵列还包含服务器版本和有效负载。否则,如果没有NOTIFY 正在等待,则返回FALSE
。
示例
示例#1 PostgreSQL NOTIFY 消息
<?php?
$conn?=?pg_pconnect("dbname=publisher");
if?(!$conn)?{
??echo?"An?error?occurred.\n";
??exit;
}
//?Listen?'author_updated'?message?from?other?processes
pg_query($conn,?'LISTEN?author_updated;');
$notify?=?pg_get_notify($conn);
if?(!$notify)?{
??echo?"No?messages\n";
}?else?{
??print_r($notify);
}
?>
扩展内容
- pg_get_pid() - 获取后端的进程ID
← pg_free_result
pg_get_pid →
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com