|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-09-23 10:21 UTC] edink at emini dot dk
[2005-09-23 10:21 UTC] wez@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Dec 17 19:00:02 2025 UTC |
Description: ------------ When calling PDO::prepare() on a query that is in some way invalid (references a table that doesn't exist, has a syntax error, etc), prepare() quietly returns null instead of returning a PDOStatement object or throwing an exception. This makes it awfully hard to debug anything, since the only error message you get is a "null or not an object" error when you call execute() on what you think is a PDOStatment. prepare() should throw an exception when the sql query is malformed. Reproduce code: --------------- <?php try { $db = new PDO("pgsql:dbname=application user=application_php password=app"); } catch (PDOException $e) { echo "error connecting to database: " . $e->getMessage(); exit(); } $query = "select * from some_non_existant_table"; $stmt = $db->prepare($query); echo 'class name of $stmt is [' . get_class($stmt) ."]\n"; ?> Expected result: ---------------- should throw an exception Actual result: -------------- prints: class name of $stmt is []