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

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();
I then referred to the documentation and tried using the $db->table("tablename") method, but it also failed.

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

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


What version of CodeIgniter are you using @RohanxSiriya ?

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 )

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.

Theme © iAndrew 2016 - Forum software by © MyBB