pg_get_notify

(PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8)

pg_get_notifyGets SQL NOTIFY message

Descrição

pg_get_notify(PgSql\Connection$connection, int$mode = PGSQL_ASSOC): array|false

pg_get_notify() gets notifications generated by a NOTIFY SQL command. To receive notifications, the LISTEN SQL command must be issued.

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.

Registro de Alterações

VersãoDescrição
8.1.0 O parâmetro connection agora espera uma instância de PgSql\Connection; anteriormente, um resource era esperado.

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);
}
?>

Veja Também

To Top