• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DBDebug unexpected behavior

#1
Sorry, me once again.

In a model, I am trying to run bad sql commands to study the MySQLi behavior.

As the documentation says, if 'DBDebug' is false, then the execution should not be stopped
in case of MySQL errors, right?

In my case, I have the line


PHP Code:
'DBDebug'  => (ENVIRONMENT !== 'production'

and the print of the 'ENVIRONMENT' variable is 'production'.

With this setup, the execution is stopped after a dummy query to insert something
in a table that doesn't exists into the database.
When a run a correct query, everything works as expected.

Should I forgot something? As the dot in front of the 'env'... x)

Thank you!

glihm
Reply

#2
In false it will always run your SQL and should return false in case of failure**. What kind of stop are you seeing? Does the entire page crash and return white? Or do you mean it stops executing the following queries. Please provide code or more information about the matter.

That flag will enable you too see the errors messages* instead of returning false. It won't prevent bad code.

* throw as \CodeIgniter\Database\Exceptions\DatabaseException
** Haven't confirmed this.
Reply

#3
Sorry jreklund, I will try to be more explicit. Smile

1) Controller code

PHP Code:
<?php namespace App\Controllers;

use 
CodeIgniter\HTTP\RequestInterface;
use 
CodeIgniter\HTTP\ResponseInterface;

use 
App\Models\TestModel;

class 
Test extends BaseController
{
    public function 
f1()
    {
        echo 
ENVIRONMENT;
        echo 
"------<br>";

        
$tm = new TestModel();
        
$dbres $tm->test();
    }

    
//--------------------------------------------------------------------




2) Model code


PHP Code:
<?php namespace App\Models;

use 
CodeIgniter\Model;

class 
TestModel extends Model
{
    public function test()
    {
        $res $this->db->query("insert into `tw` (`name`) values ('value1');");
        echo "I want to see this print...";
        return $res;
    }



The database only contains one table, named `t1`.
If I use the correct table name,  the output generated is:

Code:
production------<br>I want to see this print...


However, if I run the code as it is in the model (table name voluntary misstaped), the output is:

Code:
production------<br>


I have checked the logs, and the result is a CRITICAL log:


Code:
CRITICAL - 2020-02-15 21:57:53 --> Table 'ci4.tw' doesn't exist
#0 C:\Users\glihm\source\repos\internshipwanted\backend\system\Database\MySQLi\Connection.php(330): mysqli->query('insert into `tw...')
#1 C:\Users\glihm\source\repos\internshipwanted\backend\system\Database\BaseConnection.php(738): CodeIgniter\Database\MySQLi\Connection->execute('insert into `tw...')
#2 C:\Users\glihm\source\repos\internshipwanted\backend\system\Database\BaseConnection.php(666): CodeIgniter\Database\BaseConnection->simpleQuery('insert into `tw...')
#3 C:\Users\glihm\source\repos\internshipwanted\backend\app\Models\TestModel.php(11): CodeIgniter\Database\BaseConnection->query('insert into `tw...')
#4 C:\Users\glihm\source\repos\internshipwanted\backend\app\Controllers\Test.php(19): App\Models\TestModel->test()
#5 C:\Users\glihm\source\repos\internshipwanted\backend\system\CodeIgniter.php(847): App\Controllers\Test->f1()
#6 C:\Users\glihm\source\repos\internshipwanted\backend\system\CodeIgniter.php(338): CodeIgniter\CodeIgniter->runController(Object(App\Controllers\Test))
#7 C:\Users\glihm\source\repos\internshipwanted\backend\system\CodeIgniter.php(246): CodeIgniter\CodeIgniter->handleRequest(NULL, Object(Config\Cache), false)
#8 C:\Users\glihm\source\repos\internshipwanted\backend\public\index.php(45): CodeIgniter\CodeIgniter->run()
#9 {main}


I have checked my CodeIgniter3 code, and I used to check the result of the database query.
In the present case, I can't do it.

The '.env' file is the default one, I have adjust the database password and user only.

Thank you for your lights, and will still looking for a configuration that I am missing.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.