Re: Return codes on PDO insert
| From: | R. Eric Wheeler | Date: | Thu, 25 Mar 2021 21:18:15 +0000 |
| Subject: | Re: Return codes on PDO insert | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-327526@lists.php.net to get a copy of this message | ||
Paul,
I think what you are looking for is https://www.php.net/manual/en/pdo.setattribute.php
Specifically PDO::ATTR_ERRMODE.
Or are you saying that PDO::errorCode() had no errors?
On 3/25/21 1:51 PM, Paul M Foster wrote:
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