Doc #77414 [Opn->Nab]: PDO __construct does not thrown an exception by default
| From: | peehaa@php.net | Date: | Sat, 05 Jan 2019 22:18:41 +0000 |
| Subject: | Doc #77414 [Opn->Nab]: PDO __construct does not thrown an exception by default | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-16298@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=77414&edit=1
ID: 77414
Updated by: peehaa@php.net
Reported by: admin at torntech dot com
Summary: PDO __construct does not thrown an exception by
default
-Status: Open
+Status: Not a bug
Type: Documentation Problem
Package: Documentation problem
Operating System: n/a
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
The constructor *does* throw exceptions by default.
https://3v4l.org/0t0Sl
> The documentation should include information about the PDO::ATTR_ERRMODE attribute being set to
> PDO::ERRMODE_SLIENT by default and that an exception is thrown only when the PDO::ATTR_ERRMODE
> attribute is set to PDO::ERRMODE_EXCEPTION.
You cannot set it before creating an instance of PDO.
Previous Comments:
------------------------------------------------------------------------
[2019-01-05 19:48:35] admin at torntech dot com
Description:
------------
---
From manual page: https://php.net/pdo.construct
---
The description of Errors/Exceptions states "PDO::__construct() throws a PDOException if the
attempt to connect to the requested database fails."
However the default PDO::ATTR_ERRMODE for PDO is PDO::ERRMODE_SILENT, which requires the use of
PDO::errorInfo() or PDO::errorCode() and does not throw an exception as indicated
The documentation should include information about the PDO::ATTR_ERRMODE attribute being set to
PDO::ERRMODE_SLIENT by default and that an exception is thrown only when the PDO::ATTR_ERRMODE
attribute is set to PDO::ERRMODE_EXCEPTION.
Test script:
---------------
new PDO ("mysql:localhost; dbname=test", "root", "");
//invalid DSN usage
Expected result:
----------------
An exception to be thrown
Actual result:
--------------
No Exception is thrown by default due to PDO::ERRMODE_SLIENT
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=77414&edit=1