Re: Return codes on PDO insert

[email protected] ("R. Eric Wheeler")
Newsgroups php.general
Message-ID <[email protected]>
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
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.