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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 17 01:01:33 2025 UTC