• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Catch database error message

#1
Sad 
I have error message when try to access my controller
PHP Code:
A PHP Error was encountered
Severity
Notice
Message
: Array to string conversion
Filename
controllers/Test.php
Line Number
94 

this is my controller in CodeIgniter 2.x and worked :
PHP Code:
$dsn $_POST['mysql_db_driver'].'://'.$_POST['db_username'].':'.$_POST['db_password'].'@'.$_POST['mysql_db_host'].'/'.$_POST['mysql_db_name'];
                
$this->db $this->load->database($dsnTRUE);
                if (!empty(
$this->db) && $this->db->conn_id !== FALSE) {
                    
$db_error $this->db->_error_message();
                    if(!
file_exists(FCPATH.'sample.sql')) {
                        
$db_error.= '<br /'.$this->db->_error_message();
                    } 

and I change it in CodeIgniter 3.0 to :
PHP Code:
$dsn $_POST['mysql_db_driver'].'://'.$_POST['db_username'].':'.$_POST['db_password'].'@'.$_POST['mysql_db_host'].'/'.$_POST['mysql_db_name'];
                
$this->db $this->load->database($dsnTRUE);
                if (!empty(
$this->db) && $this->db->conn_id !== FALSE) {
                    
$db_error $this->db->error();
                    if(!
file_exists(FCPATH.'sample.sql')) {
                        
$db_error.= '<br /'.$this->db->error();
                    } 

Line number 94 is $db_error = $this->db->error();

Please help me Sad Sad
Reply

#2
(08-29-2015, 07:51 AM)popay Wrote: I have error message when try to access my controller






PHP Code:
A PHP Error was encountered
Severity
Notice
Message
: Array to string conversion
Filename
controllers/Test.php
Line Number
94 

this is my controller in CodeIgniter 2.x and worked :






PHP Code:
$dsn $_POST['mysql_db_driver'].'://'.$_POST['db_username'].':'.$_POST['db_password'].'@'.$_POST['mysql_db_host'].'/'.$_POST['mysql_db_name'];
 
$this->db $this->load->database($dsnTRUE);
 if (!empty(
$this->db) && $this->db->conn_id !== FALSE) {
 
$db_error $this->db->_error_message();
 if(!
file_exists(FCPATH.'sample.sql')) {
 
$db_error.= '<br /'.$this->db->_error_message();
 } 

and I change it in CodeIgniter 3.0 to :






PHP Code:
$dsn $_POST['mysql_db_driver'].'://'.$_POST['db_username'].':'.$_POST['db_password'].'@'.$_POST['mysql_db_host'].'/'.$_POST['mysql_db_name'];
 
$this->db $this->load->database($dsnTRUE);
 if (!empty(
$this->db) && $this->db->conn_id !== FALSE) {
 
$db_error $this->db->error();
 if(!
file_exists(FCPATH.'sample.sql')) {
 
$db_error.= '<br /'.$this->db->error();
 } 

Line number 94 is $db_error = $this->db->error();

Please help me Sad Sad

According to CI doc $this->db->error() returns an array containing its code and message.

PHP Code:
// PHP 5.4.0
$db_error .= '<br />' $this->db->error()['code'] . $this->db->error()['message']; 

http://www.codeigniter.com/user_guide/da...ing-errors
Reply

#3
Code:
A PHP Error was encountered
Severity: Notice
Message: Array to string conversion
Filename: controllers/Test.php
Line Number: 95
Backtrace:
File: C:\xampp\htdocs\test\application\controllers\test.php
Line: 95
Function: _error_handler

File: C:\xampp\htdocs\test\index.php
Line: 296
Function: require_once

Code:
Configuration doesn't saved
Array
0
0

Still get error message Array to string conversion  Sad  Sad  Sad  Sad
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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