简体   繁体   中英

Issue with codeigniter select query

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.

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);
}
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM