As requested I reformat the question:
For the following code:
$newPDO=new PDO($DSN,$USER,$PASS);
$newPDO->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
$SQL='SOME SQL STATEMENT MAYBE FAULTY';
try{
$Query=$newPDO->Prepare($SQL)
$Success=$Query->execute();
if(!$Success)
echo('A');
}
catch(PDOException $e)
{
echo('B');
}
Question is, is it possible to see 'A' printed? Will the answer varies for different type of $SQL
like select or insert?
Original question:
- First I set the attribute to PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION, so that, I think, when execute() encounters an error from the DB, it should throw an exception.
Then I realized that if that's true, I may not even have to check the return of execute() as long as an exception thrown is the same as a 'false' returned. I just need to catch from outside. If nothing caught the query should be ok.
But I am not sure about this as execute() does not throw exception according to the manual by default. I tried several operations like duplicate PK and unique constraint violation when I insert something. my assertion is supported: PDO will throw an exception and I can get the detaield error msg from DB. However I don't know whether this is a universal truth. Is it possible to get a false from execute(), and no PDOEXCEPTION thrown when I have set ERRMODE to maximum? *