Skip to content

Commit 97ecf2f

Browse files
committed
Complete the proposed changes from PR bcit-ci#4300
1 parent c424b3e commit 97ecf2f

File tree

3 files changed

+5
-17
lines changed

3 files changed

+5
-17
lines changed

system/database/DB_driver.php

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ public function __construct($params)
381381
* Initialize Database Settings
382382
*
383383
* @return bool
384+
* @throws RuntimeException In case of failure
384385
*/
385386
public function initialize()
386387
{
@@ -429,14 +430,7 @@ public function initialize()
429430
// We still don't have a connection?
430431
if ( ! $this->conn_id)
431432
{
432-
log_message('error', 'Unable to connect to the database');
433-
434-
if ($this->db_debug)
435-
{
436-
$this->display_error('db_unable_to_connect');
437-
}
438-
439-
throw new RuntimeException('Database connection failure.');
433+
throw new RuntimeException('Unable to connect to the database.');
440434
}
441435
}
442436

@@ -751,14 +745,7 @@ public function query($sql, $binds = FALSE, $return_object = NULL)
751745
*/
752746
public function simple_query($sql)
753747
{
754-
if ( ! $this->conn_id)
755-
{
756-
if ( ! $this->initialize())
757-
{
758-
return FALSE;
759-
}
760-
}
761-
748+
empty($this->conn_id) && $this->initialize();
762749
return $this->_execute($sql);
763750
}
764751

user_guide_src/source/changelog.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Release Date: Not Released
1313

1414
- Database
1515

16-
- CI_DB_driver::initialize() throws a "Database connection failure." RuntimeException if couldn't connect to the database.
16+
- Failure to initialize a database connection will now throw a ``RuntimeException``.
1717

1818

1919
Version 3.0.4

user_guide_src/source/database/db_driver_reference.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ This article is intended to be a reference for them.
1919
2020
:returns: TRUE on success, FALSE on failure
2121
:rtype: bool
22+
:throws: RuntimeException In case of failure
2223

2324
Initialize database settings, establish a connection to
2425
the database.

0 commit comments

Comments
 (0)