php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #77414 PDO __construct does not thrown an exception by default
Submitted: 2019-01-05 19:48 UTC Modified: 2019-01-05 22:18 UTC
From: admin at torntech dot com Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: Irrelevant OS: n/a
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 !
Your email address:
MUST BE VALID
Solve the problem:
10 + 9 = ?
Subscribe to this entry?

 
 [2019-01-05 19:48 UTC] 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



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-01-05 22:18 UTC] peehaa@php.net
-Status: Open +Status: Not a bug
 [2019-01-05 22:18 UTC] peehaa@php.net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 04:01:30 2024 UTC