php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39967 PDO fails to report error
Submitted: 2006-12-27 22:14 UTC Modified: 2007-01-11 10:00 UTC
From: rodricg at sellingsource dot com Assigned:
Status: Not a bug Package: PDO related
PHP Version: 5CVS-2006-12-28 (snap) OS: Linux
Private report: No CVE-ID: None
 [2006-12-27 22:14 UTC] rodricg at sellingsource dot com
Description:
------------
With a php linked against libmysqlclient.so.15 (from mysql 
5.0.30) connecting to a mysql 4.x server PDO fails to 
report errors.

Reproduce code:
---------------
<?php
$pdo = new PDO('mysql:host=localhost;port=3306;dbname=mysql', 'root', '');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$sql = "selec Host, User, Password from user";
$qry = $pdo->query($sql);
$qry->setFetchMode(PDO::FETCH_OBJ);

foreach($qry as $row)
{
	print_r($row);
}
?>

Expected result:
----------------
Fatal error: Uncaught exception 'PDOException' with 
message 'SQLSTATE[42000]: Syntax error or access 
violation: 1064 You have an error in your SQL syntax; 
check the manual that corresponds to your MySQL server 
version for the right syntax to use near 'selec Host, 
User, Password from user' at line 1' in /root/bug.php:6
Stack trace:
#0 /root/bug.php(6): PDO->query('selec Host, Use...')
#1 {main}
  thrown in /root/bug.php on line 6


Actual result:
--------------
Fatal error: Call to a member function setFetchMode() on a 
non-object in /root/bug.php on line 7

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-12-28 00:05 UTC] iliaa@php.net
Please try using this CVS snapshot:

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

Seems to work fine in latest CVS
 [2006-12-28 16:57 UTC] rodricg at sellingsource dot com
Apparently I misspoke and am only experiencing this against the 4.0 server, 4.1 appears to be working.

::root@ds02::8::/usr/src/php/php5.2-200612281530
Thu Dec 28 08:37:16 # /opt/php-snap/bin/php /root/bug.php

Fatal error: Call to a member function setFetchMode() on a non-object in /root/bug.php on line 7

::root@ds02::8::/usr/src/php/php5.2-200612281530
Thu Dec 28 08:38:54 # mysql -hxxxxxxxxx.xxx -uxxxxxxx -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2032902
Server version: 4.0.25-log


::root@ds02::8::/usr/src/php/php5.2-200612281530
Thu Dec 28 08:44:56 # /opt/php-snap/bin/php /root/bug.php

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'selec Host, User, Password from user' at line 1' in /root/bug.php:6
Stack trace:
#0 /root/bug.php(6): PDO->query('selec Host, Use...')
#1 {main}
  thrown in /root/bug.php on line 6

::root@ds02::8::/usr/src/php/php5.2-200612281530
Thu Dec 28 08:45:34 # mysql -hxxxxx.xxxxxxxxx.xxx -P3309 -uxxxxxxxx -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 627531
Server version: 4.1.10-standard-log
 [2006-12-29 00:12 UTC] iliaa@php.net
I suspect it is caused by MySQL not returning an error code or 
doing so in a non-standard fashion. With 4.1 and 5.0 versions 
I get the expected exception thrown.
 [2006-12-29 19:10 UTC] rodricg at sellingsource dot com
Do you experience the same behavior as me (no error 
reported) against a 4.0 server? Or is it specific to my 
environment / setup?
 [2006-12-30 02:04 UTC] iliaa@php.net
Unfortunately I do not have 4.0 server setup, But on all the 
version of MySQL i have access to PDO reports the expected 
error.
 [2007-01-02 16:41 UTC] rodricg at sellingsource dot com
I am experiencing this against 2 different servers with versions 4.0.26-standard-log and 4.0.25-log.  Please verify that I am wrong before marking this as bogus.  At the very least the documentation should indicate this deficiency.
 [2007-01-11 10:00 UTC] tony2001@php.net
>At the very least the documentation should indicate this deficiency.
I believe PHP documentation is wrong place for documenting MySQL deficiencies. If the error disappears when using different library version (and the same PHP source code) then the problem is clearly in the library.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Apr 29 13:01:30 2024 UTC