Every so often I try to use PDO under PHP5, and every time I run in to basic functionality problems with no ability to find out what’s going on under the hood. A recent example:
$dbh = new PDO(‘mysql:host=localhost;dbname=db’, “user”,”pass”);
$stmt = $dbh->prepare(“SELECT * FROM table where service_type = ? and name = ? “);
if ($stmt->execute(array(2,$short_name))) {
….
The ‘if’ line is giving me a FATAL_ERROR “accessing execute() method on a non-object”.
So the ‘prepare’ statement didn’t work. But why not? Throwing a try/catch around the prepare statement caught nothing – it just happily went on to try to execute the sql against $stmt even though it wasn’t an object. How do you debug this stuff? There’s no docs I can find on debugging this sort of behaviour, and given that PDO is a few years old, I shouldn’t have to. BTW, I know it’s out of date – this is 5.1.6, so I am going to try to update today.
Another thing – how do you see what the final SQL statement sent to the DB would be? Again – never seen any docs on this. Go ahead – embarrass me and show me where this is documented so I look like a complete jerk.
If PDO was as good as it should be, I don’t think there’d be such a movement underway to rewrite a PDO2, which appears to be the case.
Also, in the docs, there’s *mention* of “if prepare doesn’t work you’ll get back FALSE”, but *no* examples show ‘proper’ behaviour of checking if your $stmt is an object or FALSE. Some examples do show try/catch, IIRC, but that doesn’t seem to work (again, at least in 5.1.6).
Prove me wrong, someone, please.