Gets last error from PDO

Uses statement errorInfo() to return error message.

php
fork add to bundle source
function mysql_pdo_error($statement, $pdo) { return $statement ? $statement->errorInfo()[2] : $pdo->errorInfo()[2]; }

usage

load_function('mysql_pdo_error'); $pdo = new PDO('mysql:host=127.0.0.1;dbname=db', 'user', 'pwd'); $stmt = $pdo->query('SELECT BAD'); echo mysql_pdo_error($stmt, $pdo); // Unknown column 'BAD' in 'field list'
← how to use this in app?
create log ...inout