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

Dev: Database config that always throws Exceptions #6132

Closed
kenjis opened this issue Jun 16, 2022 · 3 comments
Closed

Dev: Database config that always throws Exceptions #6132

kenjis opened this issue Jun 16, 2022 · 3 comments

Comments

@kenjis
Copy link
Member

kenjis commented Jun 16, 2022

Now in the development environment CI throws Exceptions when DB errors occur,
but in the production environment, CI returns false.

So most devs don't check query return values, and DB errors in the production environment
will be hidden by the configuration.

See #6115 (comment)

Ref

@kenjis
Copy link
Member Author

kenjis commented Jun 17, 2022

@MGatner I've checked all $DBDebug, and confirmed the behavior changes are only whether throwing an exception or returning false (or just ignored).

And I found that if I always want Exceptions thrown, all I need to do is this:

--- a/app/Config/Database.php
+++ b/app/Config/Database.php
@@ -39,7 +39,7 @@ class Database extends Config
         'DBDriver' => 'MySQLi',
         'DBPrefix' => '',
         'pConnect' => false,
-        'DBDebug'  => (ENVIRONMENT !== 'production'),
+        'DBDebug'  => true,
         'charset'  => 'utf8',
         'DBCollat' => 'utf8_general_ci',
         'swapPre'  => '',

The only issue is the name of the property DBDebug is not good.

--- a/system/Database/BaseConnection.php
+++ b/system/Database/BaseConnection.php
@@ -124,7 +124,7 @@ abstract class BaseConnection implements ConnectionInterface
     /**
      * Debug flag
      *
-     * Whether to display error messages.
+     * Whether to throw Exception or not when an error occurs.
      *
      * @var bool
      */

@MGatner
Copy link
Member

MGatner commented Jun 17, 2022

Oh nice! That's a lot easier than I expected. Yes I will switch all my projects to true, much better to have the actual database error then some strange code errors farther down the stack.

I agree the name is unfortunate but probably not worth fiddling with if the functionality is all there.

@kenjis
Copy link
Member Author

kenjis commented Jun 21, 2022

Yes, DBDebug is not a good name, but changing the name would have too great an impact,
and gain almost nothing.

@kenjis kenjis closed this as completed Jun 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants