Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI_DB_driver->simple_query() doesn't handle the return of CI_DB_driver->initialize() when db_debug options is FALSE #4223

Merged
merged 4 commits into from
Nov 9, 2015

Conversation

j0inty
Copy link
Contributor

@j0inty j0inty commented Nov 8, 2015

Overview description

Hi @ll,

today I wanted to test my rewritten ci error pages. When I was testing the ENVIROMENT "production", my database configuration will set db_debug to false and I noticed a FATAL error in my php_error.log. :(

I found out that in file system/database/DB_driver.php:777 (the function simple_query() does not respect the return value from $this->initialize(). The $this->initialize() normally never come back on a database connection error because it calls the CI_DB_driver->display_error() method WHEN db_debug option is set to TRUE.

In my production ENV the db_debug is set to FALSE so $this->initialize() returns me an FALSE but simply_query silent discard the return value and call execute(). !!_"*! ;)

regards
j0inty

Steps to reproduce

Use session with qb->pdo->pgsql
$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 14440;
$config['sess_save_path'] = 'ci_sessions';
$config['sess_match_ip'] = TRUE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = TRUE;
config/database.php options
  1. $db['default']['db_debug'] = (ENVIRONMENT !== 'production') // I use here the condition
  2. $active_group = 'default';
    $query_builder = TRUE;
  1. Now simulate that the database is not available and reload the CI project.
  2. Internal Server Error 500 (php_error.log and ci logging has now the error message from PHP logged)

Actual results

CI Error Log Entry:
ERROR - 2015-11-08 19:24:17 --> Unable to connect to the database
ERROR - 2015-11-08 19:48:27 --> Severity: Error --> Call to a member function query() on boolean F:\workspace\postfixadmin-ng\build\dev\system\database\drivers\pdo\pdo_driver.php 181
PHP error_log entry
[08-Nov-2015 19:48:27 Europe/Berlin] PHP Fatal error:  Call to a member function query() on boolean in F:\workspace\postfixadmin-ng\build\dev\system\database\drivers\pdo\pdo_driver.php on line 181
[08-Nov-2015 19:48:27 Europe/Berlin] PHP Stack trace:
[08-Nov-2015 19:48:27 Europe/Berlin] PHP   1. {main}() F:\workspace\postfixadmin-ng\build\dev\index.php:0
[08-Nov-2015 19:48:27 Europe/Berlin] PHP   2. require_once() F:\workspace\postfixadmin-ng\build\dev\index.php:287
[08-Nov-2015 19:48:27 Europe/Berlin] PHP   3. Dashboard->__construct() F:\workspace\postfixadmin-ng\build\dev\system\core\CodeIgniter.php:500
[08-Nov-2015 19:48:27 Europe/Berlin] PHP   4. PA_Controller->__construct() F:\workspace\postfixadmin-ng\build\dev\application\controllers\dashboard.php:22
[08-Nov-2015 19:48:27 Europe/Berlin] PHP   5. CI_Controller->__construct() F:\workspace\postfixadmin-ng\build\dev\application\core\PA_Controller.php:30
[08-Nov-2015 19:48:27 Europe/Berlin] PHP   6. CI_Loader->initialize() F:\workspace\postfixadmin-ng\build\dev\system\core\Controller.php:79
[08-Nov-2015 19:48:27 Europe/Berlin] PHP   7. CI_Loader->_ci_autoloader() F:\workspace\postfixadmin-ng\build\dev\system\core\Loader.php:157
[08-Nov-2015 19:48:27 Europe/Berlin] PHP   8. CI_Loader->library() F:\workspace\postfixadmin-ng\build\dev\system\core\Loader.php:1324
[08-Nov-2015 19:48:27 Europe/Berlin] PHP   9. CI_Loader->library() F:\workspace\postfixadmin-ng\build\dev\system\core\Loader.php:202
[08-Nov-2015 19:48:27 Europe/Berlin] PHP  10. CI_Loader->_ci_load_library() F:\workspace\postfixadmin-ng\build\dev\system\core\Loader.php:218
[08-Nov-2015 19:48:27 Europe/Berlin] PHP  11. CI_Loader->_ci_load_library() F:\workspace\postfixadmin-ng\build\dev\system\core\Loader.php:1048
[08-Nov-2015 19:48:27 Europe/Berlin] PHP  12. CI_Loader->_ci_load_stock_library() F:\workspace\postfixadmin-ng\build\dev\system\core\Loader.php:1003
[08-Nov-2015 19:48:27 Europe/Berlin] PHP  13. CI_Loader->_ci_init_library() F:\workspace\postfixadmin-ng\build\dev\system\core\Loader.php:1140
[08-Nov-2015 19:48:27 Europe/Berlin] PHP  14. CI_Session->__construct() F:\workspace\postfixadmin-ng\build\dev\system\core\Loader.php:1247
[08-Nov-2015 19:48:27 Europe/Berlin] PHP  15. session_start() F:\workspace\postfixadmin-ng\build\dev\system\libraries\Session\Session.php:140
[08-Nov-2015 19:48:27 Europe/Berlin] PHP  16. CI_Session_database_driver->read() F:\workspace\postfixadmin-ng\build\dev\system\libraries\Session\Session.php:140
[08-Nov-2015 19:48:27 Europe/Berlin] PHP  17. CI_Session_database_driver->_get_lock() F:\workspace\postfixadmin-ng\build\dev\system\libraries\Session\drivers\Session_database_driver.php:145
[08-Nov-2015 19:48:27 Europe/Berlin] PHP  18. CI_DB_driver->simple_query() F:\workspace\postfixadmin-ng\build\dev\system\libraries\Session\drivers\Session_database_driver.php:341
[08-Nov-2015 19:48:27 Europe/Berlin] PHP  19. CI_DB_pdo_driver->_execute() F:\workspace\postfixadmin-ng\build\dev\system\database\DB_driver.php:780

Expected results

Get only the "Unable to connect ..." message in CI Log and not the "Severity: Error --> Call to a member function ..." from PHP, too.

CI Error Log Entry
ERROR - 2015-11-08 19:24:17 --> Unable to connect to the database

The project site is showing up again without to display the db error page as expected. ;)

regards
j0inty

Pull current develop branch to submit a bug report later
@@ -774,7 +774,10 @@ public function simple_query($sql)
{
if ( ! $this->conn_id)
{
$this->initialize();
if( !$this->initialize() )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if ( ! $this->initialize())

* fixed PHP code style
@@ -774,7 +774,10 @@ public function simple_query($sql)
{
if ( ! $this->conn_id)
{
$this->initialize();
if( ! $this->initialize())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still missing a space after the if ...

Also, please leave a comment after you push changes as commits don't issue notifications.

* added missing space character
@j0inty
Copy link
Contributor Author

j0inty commented Nov 9, 2015

Hi,

I added the lost space character again. Hope this does it now ;)

regards

narfbg added a commit that referenced this pull request Nov 9, 2015
CI_DB_driver->simple_query() to check initialize() return value
@narfbg narfbg merged commit 035c21a into bcit-ci:develop Nov 9, 2015
narfbg added a commit that referenced this pull request Nov 9, 2015
CI_DB_driver->simple_query() to check initialize() return value
narfbg added a commit that referenced this pull request Nov 9, 2015
@narfbg narfbg added the Bug label Nov 9, 2015
@narfbg narfbg added this to the 3.0.4 milestone Nov 9, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants