Welcome Guest, Not a member yet? Register   Sign In
What could be causing the database retrieval error?
#1

I'm using CodeIgniter 4, and I encountered an error (Call to a member function table() on null) when trying to retrieve records from the database using the following code:
$CI = & get_instance();
$CI->db->select('*');
$CI->db->from($table_name).
I then referred to the documentation and tried using the $db->table("tablename") method, but it also failed.
Reply
#2

PHP Code:
$db db_connect();
$builder $db->table($table_name);
$query $builder->get();

foreach (
$query->getResult() as $row) {
    var_dump($row);

Reply
#3

What version of CodeIgniter are you using @RohanxSiriya ?
Reply
#4

He say's he is use CodeIgniter 4.

You can not use that code with CodeIgniter 4, that's CodeIgniter 3 code.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

Ah, I missed the version reference, I guess, when I saw the mix of 3 and 4 code I just wanted to make sure.

In that case @Mni.day has the right code, though there's more variables than necessary needed.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB