There's an example, using PostgreSQL driver:

----------------------------------------------------
<?php
$sql = new PDO('pgsql:host=localhost;dbname=postgres', 'postgres', '',
array(
    PDO::ATTR_LOG_NOTICES => PDO::NOTICES_FETCH
));
var_dump($sql);

echo "getAttribute: ";
var_dump($sql->getAttribute(PDO::ATTR_LOG_NOTICES));

echo 'Notices: '; var_dump($sql->noticeInfo());

$q1 = $sql->query('CREATE OR REPLACE FUNCTION test_notice (v_int
integer) RETURNS integer AS $$
BEGIN
    RAISE NOTICE \'Sympatique % !\', v_int;
    RAISE NOTICE \'Sympatique un nouvelle fois % !\', v_int;
    RAISE NOTICE \'Génial maintenant... % \', v_int;
    RETURN 12;
END;
$$ LANGUAGE plpgsql;');

$q2 = $sql->query('SELECT * FROM test_notice(1)');
echo 'Query: '; var_dump($q2);

echo 'Notices: '; var_dump($sql->noticeInfo());
?>
----------------------------------------------------

That will return:
----------------------------------------------------
object(PDO)#1 (0) {
}
getAttribute: bool(true)
Notices: bool(false)
Query: object(PDOStatement)#3 (1) {
  ["queryString"]=>
  string(28) "SELECT * FROM test_notice(1)"
}
Notices: array(3) {
  [0]=>
  string(23) "NOTICE:  Sympatique 1 !"
  [1]=>
  string(40) "NOTICE:  Sympatique un nouvelle fois 1 !"
  [2]=>
  string(33) "NOTICE:  Génial maintenant... 1 "
}
Query: object(PDOStatement)#4 (1) {
  ["queryString"]=>
  string(10) "SELECT 1,2"
}
Notices: bool(false)
----------------------------------------------------

Samuel.

Le jeudi 08 octobre 2009 à 23:51 +0200, Samuel ROZE a écrit :
> Hi,
> 
> I've make a patch which insert notices concepts to PDO. It create:
> - PDO::noticeInfo() - to be like errorInfo
> - PDO::ATTR_LOG_NOTICES, the name of the PDO parameter
>       - PDO::NOTICES_FETCH - fetch notices
>       - PDO::NOTICES_NONE - don't fetch notices
> 
> The notices HashTable is emptied at each queries.
> 
> There is a patch to implements this function into PDO:
> http://www.d-sites.com/wp-content/uploads/2009/10/php-5_3-pdo-notices-managment.patch
> 
> And one other to implements notices recuperation for PostgreSQL:
> http://www.d-sites.com/wp-content/uploads/2009/10/php-5_3-pdo-pgsql-notices-managment.patch
> 
> It can be done for Oracle, i'm sure.
> 
> Thanks for feedbacks.
> Samuel.
> 


-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to