Your setAttribute () call is missing the first parameter:
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
If you have not received
Warning: PDO::setAttribute() expects exactly 2 parameters, 1 given
your error_reporting level is too low for the development server and / or you don't follow the error log or set display_errors = On (which I ever preferred; I prefer the error log to display_errors).
edit: try
<?php echo 'php version: ', phpversion(), "\n"; try { $dbh = new PDO('mysql:host=localhost;dbname=test;charset=utf8', 'localonly', 'localonly'); echo 'client version: ', $dbh->getAttribute(PDO::ATTR_CLIENT_VERSION), "\n"; echo 'server version: ', $dbh->getAttribute(PDO::ATTR_SERVER_VERSION), "\n"; $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); } catch(PDOException $err) { var_dump($err->getMessage()); die('...'); } $id = 'foo'; try { $stmt = $dbh->prepare("SELECT COUNT(*) FROM Product WHERE `non-existent_column`=?"); $stmt->bindValue(1, $id, PDO::PARAM_INT); $stmt->execute(); $row = $stmt->fetchColumn(); } catch(PDOException $err) { var_dump($err->getMessage()); var_dump($dbh->errorInfo()); die('....'); } echo 'done.';
printed on my car
php version: 5.3.5 client version: mysqlnd 5.0.7-dev - 091210 - $Revision: 304625 $ server version: 5.5.8 string(94) "SQLSTATE[42S22]: Column not found: 1054 Unknown column 'non-existent_column' in 'where clause'" array(3) { [0]=> string(5) "42S22" [1]=> int(1054) [2]=> string(54) "Unknown column 'non-existent_column' in 'where clause'" } ....
source share