array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'pdo-pgsql.setnoticecallback.php', 1 => 'Pdo\\Pgsql::setNoticeCallback', 2 => 'Set a callback to handle notice and warning messages generated by the backend', ), 'up' => array ( 0 => 'class.pdo-pgsql.php', 1 => 'Pdo\\Pgsql', ), 'prev' => array ( 0 => 'pdo-pgsql.lobunlink.php', 1 => 'Pdo\\Pgsql::lobUnlink', ), 'next' => array ( 0 => 'ref.pdo-sqlite.php', 1 => 'SQLite PDO Driver', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/pdo_pgsql/pdo/pgsql/setnoticecallback.xml', ), 'history' => array ( ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); contributors($setup); ?>

Pdo\Pgsql::setNoticeCallback

(PHP 8 >= 8.4.0)

Pdo\Pgsql::setNoticeCallbackSet a callback to handle notice and warning messages generated by the backend

说明

public Pdo\Pgsql::setNoticeCallback(?callable $callback): void

Set a callback to handle notice and warning messages generated by the backend. This includes messages emitted by PostgreSQL itself, as well as those raised by user-defined SQL functions using RAISE. Please note that the actual receipt of these messages depends on the backend setting client_min_messages.

参数

callback
If null is passed, the handler is reset to its default state.

Otherwise, the handler is a callback with the following signature:

handler(string $message): void
message
A message generated by the backend.

返回值

没有返回值。

示例

示例 #1 Pdo\Pgsql::setNoticeCallback() example

<?php
$pdo
= new Pdo\Pgsql('pgsql:dbname=test host=localhost', $user, $pass);

$pdo->exec('CREATE TABLE parent(id int primary key)');
$pdo->exec('CREATE TABLE child(id int references parent)');

$pdo->setNoticeCallback(function ($message) {
echo
$message;
});

$pdo->exec('TRUNCATE parent CASCADE');
?>

以上示例的输出类似于:

NOTICE:  truncate cascades to table "child"