I am using FluentPDO to build my queries.
When I execute an insert statement, it returns False
if it is unable to do so. However, I am unable to figure out how to retrieve the error behind the failure.
Does anyone know how to handle errors while using this library?
This is my current code...
function doInsert() {
$pdo = new PDO("mysql:dbname=blog", "root", "password");
$fpdo = new FluentPDO($pdo);
$values = [
'field1' => 'value 1',
'field2' => 'value 2',
'field3' => 'value 3',
];
$query = $fpdo->insertInto('my_table', $values)->execute();
if (!$query) {
// what to type here to determine error
}
}
This is NOT the answer, but the explanation from author (FluentPDO/BaseQuery.php Line: 98):
// At this point, $result is a PDOStatement instance, or false.
// PDO::prepare() does not reliably return errors. Some database drivers
// do not support prepared statements, and PHP emulates them. Postgres
// does support prepared statements, but PHP does not call Postgres's
// prepare function until we call PDOStatement::execute() (below).
// If PDO::prepare() worked properly, this is where we would check
// for prepare errors, such as invalid SQL.