Welcome Guest, Not a member yet? Register   Sign In
DatabaseException: You must set the database table to be used with your query
#1

(This post was last modified: 03-30-2025, 03:47 AM by Vespa.)

I get the following error
CodeIgniter\Database\Exceptions\DatabaseException
You must set the database table to be used with your query
Using the code below ( it seems to me that tables name are set )

Any hint to fix the issue? Thanks a lot

Code:
public function index(): string
{
   $model = new RegisterModel();
   $total->registrations = $model->countRegistrations();
   $this->viewData['total'] = $total;
   return view('pages/public/registers/civil/main', $this->viewData);
}
In the Model is:
Code:
namespace App\Models\Public\Registers\Civil;
use CodeIgniter\Model;
class RegisterModel extends Model
{
    protected $DBGroup = 'registers';
    protected $table_register      = 'rci_combinations';
    protected $table_registrations = 'rci_registrations';
    protected $table_aircrafts    = 'rci_aircrafts';
    protected $table_models        = 'aircraft_models';
    protected $table_manufacturers = 'aircraft_manufacturers';
    protected $table_pictures      = 'rci_images';
...
...
public function countRegistrations($p = NULL, $id = NULL)
{
    $builder = $this->db->table("$this->table_pictures");
    $builder->select("
        $this->table_register.id
        ");
       
    $builder->from("$this->table_register");
    $builder->join("$this->table_registrations", "$this->table_registrations.rid = $this->table_register.rid");
    $builder->join("$this->table_pictures", "$this->table_register.id = $this->table_pictures.id");
    $builder->join("$this->table_relations", "$this->table_relations.register_id = $this->table_register.id",'left');
    $builder->where("$this->table_registrations.icao_id", '115');

    if($p == 'operators')
    {
        $builder->groupBy("$this->table_register.rid");
        $builder->where("$this->table_relations.operator_id", $id);
    }
    $query = $builder->countAllResults();
    return $query;
}
Reply
#2

Hi Vespa, I have encountered such errors and usually in my case it was some syntax error.
Looking at the code from the mobile it looks like closing } is missing:

PHP Code:
class RegisterModel extends Model
{
...
} <----- 
Here 
Reply
#3

Where in your model do you actually connect to the database group?
I would expect to see some code like this
PHP Code:
$this->db Database::connect('registers'); 
Reply
#4

Hi, Vespa.

just remove double quotes here
$builder = $this->db->table("$this->table_pictures");
like this
$builder = $this->db->table($this->table_pictures);
Reply




Theme © iAndrew 2016 - Forum software by © MyBB