9951 explained code solutions for 126 technologies


php-pdoGet last query error with PHP PDO


$error = $pdo->errorInfo();ctrl + c
$error

will contain error details

$pdo

PDO connection object

errorInfo

returns details of last error happened


Usage example

<?php

$pdo = new PDO('mysql:host=localhost;dbname=test', 'usr', 'pwd');
$pdo->query('WRONG');

$error = $pdo->errorInfo();
print_r($error);
output
Array
(
    [0] => 42000
    [1] => 1064
    [2] => You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'WRONG' at line 1
)