php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37285 PDOConnection->exec fails silently
Submitted: 2006-05-02 21:05 UTC Modified: 2009-05-03 01:00 UTC
Votes:14
Avg. Score:4.4 ± 1.1
Reproduced:12 of 14 (85.7%)
Same Version:0 (0.0%)
Same OS:1 (8.3%)
From: vldi at yahoo dot com Assigned: wez (profile)
Status: No Feedback Package: PDO related
PHP Version: 5CVS-2006-05-02 (snap) OS: Suse 10
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
47 - 33 = ?
Subscribe to this entry?

 
 [2006-05-02 21:05 UTC] vldi at yahoo dot com
Description:
------------
PDO does not raise the exception when SQL fails.
Config is: './configure' '--prefix=/usr/local/php5' '--with-openssl' '--with-kerberos' '--with-zlib' '--with-bz2' '--enable-calendar' '--with-curl' '--with-curlwrappers' '--enable-exif' '--enable-ftp' '--with-gettext' '--with-ldap' '--with-ldap-sasl' '--with-mssql=/usr/local/freetds' '--with-mysql' '--with-mysql-sock' '--with-mysqli' '--with-unixODBC=/usr' '--with-pdo-mysql' '--with-pdo-odbc=unixODBC,/usr' '--enable-sockets' '--enable-sysvmsg' '--enable-sysvsem' '--enable-sysvshm' '--with-xsl' '--with-pear' '--disable-cgi' '--with-apxs2=/usr/local/apache2/bin/apxs' '--with-config-file-path=/etc/php.ini' '--enable-debug'

Reproduce code:
---------------
<html><body>
<?php
	$dsn = 'DRIVER=FreeTDS;SERVERNAME=server1;DATABASE=testdb;UID=user1;';
	$dbuser='foolproof';
	$dbpassword='';
	$dbh = null;
	try {
		$dbh = new PDO('odbc:'.$dsn, $dbuser, $dbpassword );
		if ( ! $dbh )  {
			print "<p>No DBH</p></body></html>";
			die();
		};
		$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
		$dbh->exec("
			create procedure pdotest
			@param_in int = null,
			@param_out int output
			as
			set @param_out = @param_in
			go
		");
	} catch ( PDOException $e ) {
		print "<p>Failed: ".$e->getMessage()."</p></body></html>";
		die();
	}
?>
<p>Succedeed</p>
</body></html>

Expected result:
----------------
Expect to either see the new  procedure created, or exception raised.

Actual result:
--------------
The page displays "Succeesed", yet no procedure created in the database.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-05-04 14:59 UTC] smlerman at gmail dot com
5.1.2 using MySQL.

This also appears to be a problem with prepared queries. $stmt->execute() returns false, but no exception is raised. Both $db->errorInfo() and $stmt->errorInfo() show no error (code '00000'). The database log shows the query being prepared, but doesn't show the execution attempt.

$res = $stmt->execute();
echo "<pre>"; var_dump($res, $stmt->errorInfo(), $db->errorInfo()); echo "</pre>";

bool(false)
array(1) {
  [0]=>
  string(5) "00000"
}
array(1) {
  [0]=>
  string(5) "00000"
}
 [2006-05-04 15:57 UTC] smlerman at gmail dot com
Well, I found the problem with my code.

$stmt->bindValue(':something', $some_array, PDO::PARAM_INT);

Obviously, trying to bind an array as an integer doesn't work too well. Some type of error message/exception would be nice to see though.
 [2006-06-02 18:23 UTC] moy at ivsol dot net
Im having the same issue.
PHP version: PHP 5.1.4-pl0-gentoo with Hardening-Patch 0.4.9 (cli) (built: May 16 2006 16:51:09)

I dont think It matters having Hardening Patch.

I have used the following code to test:

<?php
/*bug: 37285*/
try
{
    $pdo          = new PDO('pgsql:dbname=iss-callmanager;user=postgres;password=voip123admin;host=localhost');
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    /* the following statement have SQL error, no space between SET value and WHERE clause */
    $statement    = $pdo->prepare('UPDATE patterns SET pattern_name = :pattern_nameWHERE pattern_id = :pattern_id');
    $pattern_name = 'SIP Internas';
    $pattern_id   = 4;
    $values       = array(':pattern_name' => $pattern_name, ':pattern_id' => $pattern_id);
    $result       = $statement->execute($values);
    var_dump($result);
    var_dump($statement->errorInfo());
}
catch ( PDOException $error )
{
    echo $error->getMessage() . "\n"; 
}
?>

I was expecting an exception, or the query executed successfully, nothing happens. I have noticed that postgresql executes the query correctly If I put the literal query in the command line, no matter that no space exists between the SET value and the starting of the WHERE clause.
 [2007-07-11 15:48 UTC] pickscrape at gmail dot com
I am able to reproduce this using the following example:

<?php
    $objDB = new PDO('mysql:dbname=mysql;host=127.0.0.1', 'root', '');

    $objDB->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    $objStmt = $objDB->prepare('I do not even remotely resemble a query.');

    $objStmt->execute();
?>

The key in my case is in changing the connection parameters. If I'm connecting to a MySQL 5 server, the exception is thrown correctly. If I'm connecting to a MySQL 4.0 server, no exception is thrown.

At the client end I have MySQL 5 libraries installed, running bundled PDO via PHP 5.2.2.
 [2009-04-25 14:38 UTC] jani@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/


 [2009-05-03 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2014-03-25 14:54 UTC] contact at nicolasbouliane dot com
I have the same bug in 5.3.19 on CentOS when I use dbLib to connect to SQL Server 2008. I get warnings, but blatantly invalid queries don't raise exception, despite setting ATTR_ERRMODE. The attribute is set, but it has no effect.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 18:01:29 2024 UTC