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
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: admin at torntech dot com
New email:
PHP Version: OS:

 

 [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-2020 The PHP Group
All rights reserved.
Last updated: Sun Aug 09 17:01:23 2020 UTC