News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Lorna Mitchell's Blog:
Handling SQL Errors in PDO
November 16, 2011 @ 09:43:34

Lorna Mitchell has a quick new post showing one way to handle SQL errors in PDO that could pop up because of badly written/generated SQL statements.

I love PHP's PDO (PHP Data Objects) extension; it gives a consistent, object-oriented interface to handling all kinds of relational database backends. One thing that annoys me is that the MySQL driver for PDO defaults to a silent error mode which can make SQL errors tricky to spot!

In her two code snippets she shows a failing PDO request (that fails silently) and a method for catching this issue - checking the result of the "errorCode" method to see if it equals "0" (zero). If there were errors, you can use the "errorInfo" function to get to them. This will return the SQL error code, the driver-specific error code and a driver-specific error message.

0 comments voice your opinion now!
pdo error handling errorcode errorinfo tutorial


blog comments powered by Disqus

Similar Posts

Dave Marshall' Blog: Asynchronous cache priming with progress bars via Gearman, Memcache and Dojo

JSLabs Blog: How to turn a php script to an exe...for free

Nicolas Grekas (on Github): Improved handling of HTTP requests in PHP

Fabien Potencier's Blog: Create your own framework... on top of the Symfony2 Components (part 11)

Marcelo Gornstein's Blog: Making your ivr nodes (call) flow with PAGI


Community Events

Don't see your event here?
Let us know!


podcast unittest framework middleware library interview series community laravel5 voicesoftheelephpant release language wordpress conference extension laravel introduction development opinion api

All content copyright, 2015 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework