|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchespgsqlSetNoticeCallback.8.diff (last revision 2021-03-11 17:35 UTC by guillaume-php at outters dot eu)pgsqlSetNoticeCallback.7.diff (last revision 2019-10-02 05:05 UTC by guillaume-php at outters dot eu) Pull Requests
Pull requests:
HistoryAllCommentsChangesGit/SVN commits
[2019-10-02 05:05 UTC] guillaume-php at outters dot eu
[2019-10-13 23:17 UTC] guillaume-php at outters dot eu
[2019-12-04 06:21 UTC] guillaume-php at outters dot eu
[2021-03-11 17:35 UTC] guillaume-php at outters dot eu
[2021-03-11 23:24 UTC] guillaume-php at outters dot eu
[2023-02-02 06:07 UTC] test at gmail dot com
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 06 00:00:02 2025 UTC |
Description: ------------ There is currently no way to receive PostgreSQL's notices PHP-side. A PQsetNoticeProcessor has been defined 15 years ago to the empty function _pdo_pgsql_notice, to prevent libpq's default behaviour (fprintfing to stderr)). Passing notices to PHP could prove useful, allowing e.g. user-defined RAISE NOTICE in PL/pgSQL long-running code to provide feedback. A user-space callback would give more control on what to do with the message (compared to the exec-then-fetch method of non-PDO pgsql driver's pg_last_notice)… not the least being the live feedback ability. Test script: --------------- function disp($message) { echo trim($message)."\n"; } $db = new PDO('pgsql:host=localhost;port=5432;dbname=…', '', ''); if(method_exists($db, 'pgsqlSetNoticeCallback')) $db->pgsqlSetNoticeCallback('disp'); $db->beginTransaction(); $db->exec("create temporary table t (a varchar(3))"); $db->exec("create function hey() returns trigger as \$\$ begin new.a := 'oh'; raise notice 'I tampered your data, did you know?'; return new; end; \$\$ language plpgsql"); $db->exec("create trigger hop before insert on t for each row execute procedure hey()"); $db->exec("insert into t values ('ah')"); print_r($db->query("select * from t")->fetchAll()); Expected result: ---------------- I would like to know that a trigger triggered ("I tampered your data, did you know?"). Actual result: -------------- Only tcpdump will display my carefully-crafted RAISE NOTICE.