Return codes on PDO insert
| From: | Paul M Foster | Date: | Thu, 25 Mar 2021 20:51:28 +0000 |
| Subject: | Return codes on PDO insert | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-327525@lists.php.net to get a copy of this message | ||
I'm using a database class which wraps around the PDO classes, using a
SQLite3 database. I wrote some PHP to insert a record, and it didn't
insert, but no error was issued. Turns out I violated a constraint on the
table-- I'd left a field blank, and the column had a NOT NULL constraint.
I fixed the code to fill in that field. But I can't figure out why PDO
doesn't throw an error code when an insert fails due to a failed
constraint. I deliberately wrote some code to violate the constraint, and
inserted some code into the database class to dump out with whatever code
was returned from the execute() call. A failed insert yielded a 0000 code
(no error). So it's not my class.
Am I missing something? I would think the PDO driver would issue a (bad)
error code on a failed (constraint) insert. Is this not expected behavior?
Or is the SQLite3 back end at fault for not issuing an error?
Paul
--
Paul M. Foster
http://noferblatz.com
http://quillandmouse.com