pg_get_notify
(PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8)
pg_get_notify — Gets SQL NOTIFY message
Descrição
pg_get_notify(PgSql\Connection $connection
, int $mode
= PGSQL_ASSOC
): array|false
Parâmetros
-
connection
-
Uma instância de PgSql\Connection.
-
mode
-
Um parâmetro opcional que controla como o array retornado será indexado.
mode
é uma constante e pode assumir os seguintes valores:
PGSQL_ASSOC
, PGSQL_NUM
e PGSQL_BOTH
.
Usando PGSQL_NUM
, a função retornará um array com índices numéricos,
usando PGSQL_ASSOC
ela retornará apenas índices associativos
enquanto PGSQL_BOTH
retornará índices numéricos e associativos.
Valor Retornado
An array containing the NOTIFY
message name and backend PID.
If supported by the server, the array also contains the server version and the payload.
Otherwise if no NOTIFY
is waiting, then false
is returned.
Exemplos
Exemplo #1 PostgreSQL NOTIFY message
<?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);
}
?>