I am a code igniter noob. I have a controller like the following:
<?php
class Welcome extends Controller {
function Welcome()
{
parent::Controller();
$this->load->model('usermodel');
}
function index()
{
$res = $this->db->get('users');
die( print_r($res) );
}
}
I have a table 'users' in my database and I have triple checked my database credentials. However, the print method keeps just printing a "1". Anyone know why this simple query would not work?
Also worth noting that print_r prints out an object and i did set active_record = true in my database.php file. In case it helps, this is the output from
print_r($this->db);
prints
CI_DB_mysql_driver Object ( [dbdriver] => mysql [_escape_char] => ` [delete_hack] => 1 [_count_string] => SELECT COUNT(*) AS [_random_keyword] => RAND() [ar_select] => Array ( ) [ar_distinct] => [ar_from] => Array ( ) [ar_join] => Array ( ) [ar_where] => Array ( ) [ar_like] => Array ( ) [ar_groupby] => Array ( ) [ar_having] => Array ( ) [ar_limit] => [ar_offset] => [ar_order] => [ar_orderby] => Array ( ) [ar_set] => Array ( ) [ar_wherein] => Array ( ) [ar_aliased_tables] => Array ( ) [ar_store_array] => Array ( ) [ar_caching] => [ar_cache_exists] => Array ( ) [ar_cache_select] => Array ( ) [ar_cache_from] => Array ( ) [ar_cache_join] => Array ( ) [ar_cache_where] => Array ( ) [ar_cache_like] => Array ( ) [ar_cache_groupby] => Array ( ) [ar_cache_having] => Array ( ) [ar_cache_orderby] => Array ( ) [ar_cache_set] => Array ( ) [username] => root [password] => my_password [hostname] => localhost [database] => bhr_development [dbprefix] => [char_set] => utf8 [dbcollat] => utf8_general_ci [autoinit] => 1 [swap_pre] => [port] => [pconnect] => 1 [conn_id] => [result_id] => [db_debug] => [benchmark] => 0 [query_count] => 0 [bind_marker] => ? [save_queries] => 1 [queries] => Array ( [0] => SELECT * FROM (`users`) ) [query_times] => Array ( [0] => 0 ) [data_cache] => Array ( ) [trans_enabled] => 1 [trans_strict] => 1 [_trans_depth] => 0 [_trans_status] => [cache_on] => [cachedir] => [cache_autodel] => [CACHE] => [_protect_identifiers] => 1 [_reserved_identifiers] => Array ( [0] => * ) [stmt_id] => [curs_id] => [limit_used] => ) 1
UPDATE I tried something like:
$query = $this->db->get("users");
foreach($query->result() as $row){
echo "hello";
}
die();
with no luck. Still get:
Fatal error: Call to a member function result() on a non-object in ...welcome.php...