CodeIgniter Forums
CodeIgniter\Database\Exceptions\DatabaseException #8 You must set the database table - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: CodeIgniter\Database\Exceptions\DatabaseException #8 You must set the database table (/showthread.php?tid=77694)



CodeIgniter\Database\Exceptions\DatabaseException #8 You must set the database table - mbjino - 10-06-2020

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



RE: CodeIgniter\Database\Exceptions\DatabaseException #8 You must set the database table - InsiteFX - 10-06-2020

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

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



RE: CodeIgniter\Database\Exceptions\DatabaseException #8 You must set the database table - nc03061981 - 10-06-2020

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


RE: CodeIgniter\Database\Exceptions\DatabaseException #8 You must set the database table - mbjino - 10-08-2020

(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