470,874 Members | 1,752 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,874 developers. It's quick & easy.

[PDO] Detecting SQL errors?


One of my PHP5 scripts wouldn't run right because I didn't use the
right number of parameters in the SQL command, but PHP didn't return
any error, even after adding a try/catch section:

if(!$dbh->query($sql)->fetchColumn()) {
try {
//Expects two parameters -won't run
$sql = "INSERT INTO mytable VALUES (NULL)";

} catch (Exception $e) {
echo 'Exception raised : ', $e->getMessage(), "\n";

Is there a way to check that a SQL command completed correctly?

Thank you.
Jun 2 '08 #1
3 1796

$dbh->exec($sql) or die(print_r($dbh->errorInfo()));
Jun 2 '08 #2
Gilles Ganault wrote:

Is there a way to check that a SQL command completed correctly?
Check out those:
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

Un ordenador no es un televisor ni un microondas, es una herramienta
Jun 2 '08 #3
On Tue, 06 May 2008 00:17:14 +0200, Iván Sánchez Ortega
>Check out those:
Thanks guys. Problem solved.
Jun 2 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Bryan J Gudorf | last post: by
reply views Thread by r_topor | last post: by
7 posts views Thread by mpar612 | last post: by
6 posts views Thread by amygdala | last post: by
2 posts views Thread by webcm123 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.