Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter\Database\Exceptions\DatabaseException #8 You must set the database table
#1

I am getting the following error in a newly created project.  I have created database connection in APP/CONFIG/DATABASE.PHP. I have another project installed and running with out any issues. I am not sure what happened with this project.

Code:
CodeIgniter\Database\Exceptions\DatabaseException #8

You must set the database table to be used with your query.

SYSTEMPATH/Database/BaseConnection.php at line 972

965      * @return BaseBuilder
966      * @throws DatabaseException
967      */
968     public function table($tableName)
969     {
970         if (empty($tableName))
971         {
972             throw new DatabaseException('You must set the database table to be used with your query.');
973         }
974
975         $className = str_replace('Connection', 'Builder', get_class($this));
976
977         return new $className($tableName, $this);
978     }
979
Reply
#2

If you need to change the table you do it like this.

PHP Code:
$db      = \Config\Database::connect();
$builder $db->table('users'); 
What did you Try? What did you Get? What did you Expect?

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

This errors show when you create model extends Model and you use builder, so in your model, you have to set $this->table = 'tableName';

Learning CI4 from my works, from errors and how to fix bugs in the community

Love CI & Thanks CI Teams

Reply
#4

(10-06-2020, 11:22 AM)InsiteFX Wrote: If you need to change the table you do it like this.

PHP Code:
$db      = \Config\Database::connect();
$builder $db->table('users'); 

Thank you.That worked
Reply




Theme © iAndrew 2016 - Forum software by © MyBB