note 59357 modified in pdo.errorcode by googleguy

From: Date: Fri, 21 Sep 2012 17:50:15 +0000
Subject: note 59357 modified in pdo.errorcode by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-190952@lists.php.net to get a copy of this message
Hi,&#13;&#10;&#13;&#10;List containing all SQL-92 SQLSTATE Return Codes:&#13;&#10;http://www.unix.org.ua/orelly/java-ent/jenut/ch08_06.htm&#13;&#10;&#13;&#10;Use the following Code to let PDO throw Exceptions (PDOException) on Error.&#13;&#10;&#13;&#10;&#60;?PHP &#13;&#10;$pdo = new PDO (whatever);&#13;&#10;$pdo-&#62;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);&#13;&#10;try {&#13;&#10; $pdo-&#62;exec (&#34;QUERY WITH SYNTAX ERROR&#34;);&#13;&#10;} catch (PDOException $e) {&#13;&#10; if ($e-&#62;getCode() == &#39;2A000&#39;)&#13;&#10; echo &#34;Syntax Error: &#34;.$e-&#62;getMessage();&#13;&#10;}&#13;&#10;?&#62;&#13;&#10;&#13;&#10;Bye,&#13;&#10; Matthias --was-- Hi, List containing all SQL-92 SQLSTATE Return Codes: http://www.unix.org.ua/orelly/java-ent/jenut/ch08_06.htm Use the following Code to let PDO throw Exceptions (PDOException) on Error. <?PHP $pdo = new PDO (whatever); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); try { $pdo->exec ("QUERY WITH SYNTAX ERROR"); } catch (PDOException $e) { if ($e->getCode == '2A000') echo "Syntax Error: ".$e->getMessage(); } ?> Bye, Matthias http://php.net/manual/en/pdo.errorcode.php

« previous php.notes (#190952) next »