473,395 Members | 1,386 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

[PDO] Detecting SQL errors?

Hello

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)";

$dbh->exec($sql);
} 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 1913
Try

$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:
http://php.net/manual/en/pdo.errorcode.php
http://php.net/manual/en/pdo.errorinfo.php
Cheers,
--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

Un ordenador no es un televisor ni un microondas, es una herramienta
compleja.
Jun 2 '08 #3
On Tue, 06 May 2008 00:17:14 +0200, Iván Sánchez Ortega
<ivansanchez-alg@rroba-escomposlinux.-.punto.-.orgwrote:
>Check out those:
http://php.net/manual/en/pdo.errorcode.php
http://php.net/manual/en/pdo.errorinfo.php
Thanks guys. Problem solved.
Jun 2 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Bryan J Gudorf | last post by:
PDO, an open source python module for interfacing with RDBMS (SQL databases), has now reached 1.2.0! PDO provides an object oriented API, similar to that of ADO or JDBC, to python developers. PDO...
0
by: r_topor | last post by:
I'm just starting to use PDO for the first time under PHP 5.1. But something doesn't work right in the following situation: try { $dbh = new PDO(...); ... } catch (PDOException $e) {...
0
by: IamtheEvster | last post by:
Hi All, I am currently using PHP 5 and MySQL 5, both on Fedora Core 5. I am unable to call a MySQL stored procedure that returns output parameters using mysql, mysqli, or PDO. I'm having a...
5
by: eholz1 | last post by:
Hello Newsgroup, I have "installed" pdo using "pecl install pdo" (it intalled version 1.0.3), I have added the line "extension=pdo.so" to my php.ini file, but when I try to use the PDO db ...
7
by: mpar612 | last post by:
I am working on converting some old PHP 4 scripts to PHP 5. I used to use the PEAR DB module in PHP 4 and in PHP 5 I want to use PDO. I am using this code to connect to the DB: $dbh = new...
6
by: amygdala | last post by:
Hi there, I've build this little CMS in PHP for a client. It depends on PDO with mysql driver. Now, a few webhosts I've polled have PDO support, but only sqlite and sqlite2 drivers are...
2
by: webcm123 | last post by:
Must I use PDOStatement->setFetchMode() before each fetching data if I want to get only or usually ASSOC arrays? Perhaps, not. foreach( $stmt as $array ) { ... } It's the fastest way for...
1
by: gp | last post by:
****************************************************************************************************************************** Catchable fatal error: Object of class stdClass could not be...
0
by: WebCM | last post by:
PDO offers 3 modes of displaying errors: - silent mode - no errors - warnings - Warning: - exceptions - Exception: Which of them is the fastest and the most adequate for applications like CMS...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.