php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52414 warning catch by php before PDOException
Submitted: 2010-07-23 11:29 UTC Modified: 2015-05-24 04:22 UTC
Votes:6
Avg. Score:4.5 ± 0.5
Reproduced:6 of 6 (100.0%)
Same Version:4 (66.7%)
Same OS:0 (0.0%)
From: draeli at draeli dot com Assigned:
Status: No Feedback Package: PDO Core
PHP Version: 5.3.3 OS: Windows XP SP3
Private report: No CVE-ID: None
 [2010-07-23 11:29 UTC] draeli at draeli dot com
Description:
------------
I catch all PHP error to do my own behavior error but with this case (test out of the other code), when server is down, PHP catch an error (here a Warning) and only after catch a PDOException.

I think that an error because error message or same in two cases and too, if an Exception is launch, why do an PHP error ?

Test script:
---------------
<?php
$arrDriverOption = array();
$arrDriverOption[ \PDO::MYSQL_ATTR_INIT_COMMAND ] = 'SET NAMES UTF8';
$arrDriverOption[ \PDO::ATTR_TIMEOUT ] = 2;
new \PDO('mysql:host=localhost;port=3307;dbname=mydb', 'root', 'r', $arrDriverOption);

Expected result:
----------------
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2002] Une tentative de connexion a échoué car le parti connecté n'a pas répondu convenablement au-delà d'une certaine durée ou une connexion établie a échoué car l'hôte de connexion n'a pas répondu. ' in C:\Serveur\Apache2\htdocs\test\__web\index2.php:5 Stack trace: #0 C:\Serveur\Apache2\htdocs\test\__web\index2.php(5): PDO->__construct('mysql:host=loca...', 'root', 'r', Array) #1 {main} thrown in C:\Serveur\Apache2\htdocs\test\__web\index2.php on line 5

Actual result:
--------------
Warning: PDO::__construct() [pdo.--construct]: [2002] Une tentative de connexion a échoué car le parti connecté n'a pa (trying to connect via tcp://localhost:3307) in C:\Serveur\Apache2\htdocs\test\__web\index2.php on line 5

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2002] Une tentative de connexion a échoué car le parti connecté n'a pas répondu convenablement au-delà d'une certaine durée ou une connexion établie a échoué car l'hôte de connexion n'a pas répondu. ' in C:\Serveur\Apache2\htdocs\test\__web\index2.php:5 Stack trace: #0 C:\Serveur\Apache2\htdocs\test\__web\index2.php(5): PDO->__construct('mysql:host=loca...', 'root', 'r', Array) #1 {main} thrown in C:\Serveur\Apache2\htdocs\test\__web\index2.php on line 5

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-08-14 20:40 UTC] Felipe@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: mysql
 [2010-08-26 11:15 UTC] uw@php.net
-Status: Assigned +Status: Feedback
 [2010-08-26 11:15 UTC] uw@php.net
I do not understand.

The fatal error is standard PDO behaviour. Its because you do not catch the exception thrown by PDO. You get the very same error, for example, with SQLite:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [14] unable to open database file' in /home/nixnutz/php/php-src/branches/PHP_5_3/pdo.php:2
Stack trace:
#0 /home/nixnutz/php/php-src/branches/PHP_5_3/pdo.php(2): PDO->__construct('sqlite:/opt/dat...')
#1 {main}
  thrown in /home/nixnutz/php/php-src/branches/PHP_5_3/pdo.php on line 2
 [2010-09-27 11:10 UTC] uw@php.net
-Assigned To: mysql +Assigned To:
 [2010-09-27 11:10 UTC] uw@php.net
Not MySQL specific, if at all a bug. Second opinion needed.
 [2010-10-02 16:16 UTC] draeli at draeli dot com
-Status: Feedback +Status: Open
 [2010-10-02 16:16 UTC] draeli at draeli dot com
I'm ok with you, "The fatal error is standard PDO behaviour.", that's right but my problem isn't this message but 'warning' who appear before as say in my first message.
 [2014-01-01 12:48 UTC] felipe@php.net
-Package: PDO related +Package: PDO Core
 [2015-05-15 12:23 UTC] cmb@php.net
-Status: Open +Status: Feedback
 [2015-05-15 12:23 UTC] cmb@php.net
This issue (warning + exception) appears to have been fixed in the meantime (at least as of PHP 5.4.19). Can you confirm, please?
 [2015-05-24 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 12:01:30 2024 UTC