[PDO] Detecting SQL errors?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

    One of my PHP5 scripts wouldn't run right because I didn't use the
right number of parameters in the SQL command, but PHP didn't return
any error, even after adding a try/catch section:

if(!$dbh->query($sql)->fetchColumn()) {
    try {
        //Expects two parameters -> won't run
        $sql = "INSERT INTO mytable VALUES (NULL)";

    } catch (Exception $e) {
        echo 'Exception raised : ',  $e->getMessage(), "\n";

Is there a way to check that a SQL command completed correctly?

Thank you.

Re: Detecting SQL errors?


$dbh->exec($sql) or die(print_r($dbh->errorInfo()));

Re: [PDO] Detecting SQL errors?

Gilles Ganault wrote:

Quoted text here. Click to load it

Check out those:

Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

Un ordenador no es un televisor ni un microondas, es una herramienta

Re: [PDO] Detecting SQL errors?

On Tue, 06 May 2008 00:17:14 +0200, Iván Sánchez Ortega
Quoted text here. Click to load it

Thanks guys. Problem solved.

Site Timeline