-
xanabobana Junior Member
 
-
Posts: 30
Threads: 16
Joined: Oct 2021
Reputation:
3
Hello,
I'm doing a large migration from CI3 to CI4. I have a bunch of CI3 code that uses
PHP Code: //First turn off debugging so we can track errors $this->db->db_debug = FALSE; //do some transactions $this->db->db_debug = TRUE;
I was able to find reference to a CI4 configuration for DBDebug, https://codeigniter.com/user_guide/datab...ation.html, but I can't figure out how to set it. When I use:
PHP Code: $this->db->DBDebug = FALSE;
I get an error, Cannot access protected property CodeIgniter\\Database\\MySQLi\\Connection::$DBDebug
How can I change that property in CI4?
-
InsiteFX Super Moderator
     
-
Posts: 6,703
Threads: 341
Joined: Oct 2014
Reputation:
245
02-05-2025, 10:53 PM
(This post was last modified: 02-05-2025, 11:07 PM by InsiteFX.
Edit Reason: add content
)
app/Config/Database.php
Default:
PHP Code: /** * The default database connection. * * @var array<string, mixed> */ public array $default = [ 'DSN' => '', 'hostname' => 'localhost', 'username' => '', 'password' => '', 'database' => '', 'DBDriver' => 'MySQLi', 'DBPrefix' => '', 'pConnect' => false, 'DBDebug' => true, // <---- DBDEBUG ---- 'charset' => 'utf8mb4', 'DBCollat' => 'utf8mb4_general_ci', 'swapPre' => '', 'encrypt' => false, 'compress' => false, 'strictOn' => false, 'failover' => [], 'port' => 3306, 'numberNative' => false, 'foundRows' => false, 'dateFormat' => [ 'date' => 'Y-m-d', 'datetime' => 'Y-m-d H:i:s', 'time' => 'H:i:s', ], ];
You should be able to create a new group on the fly and change it there.
Say rename thr default group debug_on then create a new one debug_off and switch them using
the database group. Use an if statement to check if your DEBUG is on or off.
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
-
xanabobana Junior Member
 
-
Posts: 30
Threads: 16
Joined: Oct 2021
Reputation:
3
Thank you! In our CI3 code it says
//We need to turn off CI's database debugging in order to capture and handle db errors.
Do you know if this is still true in CI4? We were catching errors like this:
PHP Code: $dbError = $this->managedb->error(); $adminErrors = array( 'mysql_errorno'=>$dbError->code, 'mysql_error'=>$dbError->message, 'last_query'=>$this->managedb->last_query() );
I'm seeing in the documentation for CI4 that we can now catch errors like this:
PHP Code: if ($query->hasError()) { echo 'Code: ' . $query->getErrorCode(); echo 'Error: ' . $query->getErrorMessage(); }
So it seems that turning off DBDebug may not even be necessary in CI4?
(02-05-2025, 10:53 PM)InsiteFX Wrote: app/Config/Database.php
Default:
PHP Code: /** * The default database connection. * * @var array<string, mixed> */ public array $default = [ 'DSN' => '', 'hostname' => 'localhost', 'username' => '', 'password' => '', 'database' => '', 'DBDriver' => 'MySQLi', 'DBPrefix' => '', 'pConnect' => false, 'DBDebug' => true, // <---- DBDEBUG ---- 'charset' => 'utf8mb4', 'DBCollat' => 'utf8mb4_general_ci', 'swapPre' => '', 'encrypt' => false, 'compress' => false, 'strictOn' => false, 'failover' => [], 'port' => 3306, 'numberNative' => false, 'foundRows' => false, 'dateFormat' => [ 'date' => 'Y-m-d', 'datetime' => 'Y-m-d H:i:s', 'time' => 'H:i:s', ], ];
You should be able to create a new group on the fly and change it there.
Say rename thr default group debug_on then create a new one debug_off and switch them using
the database group. Use an if statement to check if your DEBUG is on or off.
|