Reputation: 977
In my codeigniter application try to retrive data from database. For that i use the following code
database.php:
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = "localhost";
$db['default']['username'] = "*****";
$db['default']['password'] = "****";
$db['default']['database'] = "mydbname";
$db['default']['dbdriver'] = 'mysqli';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = FALSE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
In Model.php:
$sql = "SELECT * from users";
$query = $this->db->query($sql);
print_r($query);
but it return like
CI_DB_mysqli_result Object ( [conn_id] => [result_id] => [result_array] => Array ( ) [result_object] => Array ( ) [custom_result_object] => Array ( ) [current_row] => 0 [num_rows] => [row_data] => ) array(0) { }
empty result. How can i get the result from this.
Upvotes: 1
Views: 249
Reputation: 4501
Do this:
<?php
$sql = "SELECT * from users";
$query = $this->db->query($sql);
if($query->num_rows() > 0) {
print_r($query->result_array());
} else {
$d = array();
print_r($d);
}
?>
Upvotes: 2