You are here: Re: PDOException : get the bad query with exception handler « PHP Programming Language « IT news, forums, messages
Re: PDOException : get the bad query with exception handler

Posted by Toby A Inkster on 02/20/07 15:46

Tonio wrote:

>> Maybe he wants to log it somewhere.
>
> That's it !

My only advice then would be to try extending PDO itself:

class MyPDO extends PDO
{
function query ($q)
{
try
{
return parent::query($q);
}
catch (PDOException $e)
{
$e->errorInfo[999] = $q;
throw $e;
}
}
function exec ($q)
{
try
{
return parent::exec($q);
}
catch (PDOException $e)
{
$e->errorInfo[999] = $q;
throw $e;
}
}
}

Then instead of using PDO, use MyPDO instead. When a PDOException is
thrown, you will now be able to inspect $e->errorInfo[999] to find the
cause of the error.

If you use prepared statements (and it is generally a good idea to do so!)
then you will also want to extend PDO->prepare() and PDOStatement->execute().
The only problem I forsee with that is a possible difficulty in cajoling
MyPDO->prepare() to return a MyPDOStatement object instead of a PDOStatement
object.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация