pdo does not thrown errors on simple usage faults
| From: | Meno Abels | Date: | Tue, 02 Aug 2005 14:40:07 +0000 |
| Subject: | pdo does not thrown errors on simple usage faults | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-40018@lists.php.net to get a copy of this message | ||
Hi there,
I have just begun an implementation of the PDO and have noticed an
unusual behaviour.
The following code is supplied as an example to illustrate this. The
main issue here is
that no error is thrown. There is no notice of failure at all for the
second fetch/execute which returns just an empty array.
thanks in advance
meno
<?php
$dbh = new PDO('mysql:dbname=myDatabase;host=localhost',
'myUserName', 'myPassWord');
$dbh->setAttribute(PDO_ATTR_ERRMODE,PDO_ERRMODE_WARNING);
$sql = 'SELECT id FROM my_table WHERE id > :id limit 0,10';
$sql2 = 'SELECT id, title FROM my_other_table WHERE id > :id limit 0,10';
$stmt1 = $dbh->prepare($sql);
$stmt2 = $dbh->prepare($sql2);
$stmt1->execute(array(':id'=>4));
while($row = $stmt1->fetch()){
print_r($row);
$stmt2->execute(array(':id'=>2));
$row = $stmt2->fetchAll();
print_r($row);
print_r($dbh->errorInfo());
}
?>