must be a callable, null given¶
Description¶
The PDOStatement::fetchAll() accepts a 2nd argument as a callback. That method processes the returning rows before they are returned by the method itself. By default, the method returns arrays, and doesn’t need the callback. When the callback is provided, it must be a valid callback, and, as such, can’t be null.
This error is the same as Argument #%d ($name) must be of type %s, %s given, but is specific to the PDO extension, and the PDOStatement::fetchAll(). The original problem is also the same.
Example¶
<?php
// Connection to the database
$db = new Pdo();
// Dummy valid SQL query
$stmt = $db->query('SELECT * FROM table');
try {
var_dump($stmt->fetchAll(PDO::FETCH_FUNC, NULL));
} catch (\Throwable $e) {
echo $e::class, ': ', $e->getMessage(), \PHP_EOL;
}
?>
Solutions¶
Remove the second
$callbackargument in the call to thePDOStatement::fetchAll()method.Use a valid second
$callbackargument in the call to thePDOStatement::fetchAll()method.