Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] Database Exception "Table does not exist". m8 being added before table names
#1

(This post was last modified: 01-21-2023, 10:38 AM by Vurnex.)

I'm getting an exception when trying to access a table in the database.


CodeIgniter\Database\Exceptions\DatabaseException #1146




When trying to log in, I get an exception that tells me that the table "database.m8users" does not exist. Except, that's not the name of the table in my database. The name of the table in the database is 'users' and this is also how I have it in my user model.



Now, at first I just renamed the table in the database to 'm8users' and the exception goes away. But this also happens to other tables as well. When trying to update my products table, I get the same exception saying 'database.m8products' doesn't exist. But it is also named exactly as 'products' in both the products model and the database.



Somewhere the characters 'm8' is being added before the table names when querying the database, but I can't figure out what is causing it. I suspect that it could have something to do with POST requests, as when I read data from the products table to display it on a webpage, I don't get any exceptions and the data displays just fine.



Here is one of the code snippets from the backtrace. It highlights line 49.



APPPATH/Controllers/AddProducts.php : 49   —  CodeIgniter\Controller->validate ()



Code:
44            //set rules validation form
45            $rules = [
46                'iteminput'          => 'required|min_length[3]|max_length[20]|is_unique[products.name]',
47            ];
48           
49            if($this->validate($rules)){
50                $model = new ProductsModel();

---
Below is the ProductsModel
Code:
<?php namespace App\Models;
 
use CodeIgniter\Model;
 
class ProductsModel extends Model {

    protected $table = 'products';
    protected $allowedFields = ['id','name','price','description', 'prodID'];

    public function getProducts()
    {
        $db      = \Config\Database::connect();
        $builder = $db->table('products');

        $query  = $db->query('SELECT id, name, price, description, prodID FROM products');
        $results = $query->getResultArray();

        return ($results);

    }
}


I should also point out that I'm using CodeIgniter 4.3.1 installed using Softaculous through a2 hosting with PHP 8.2. I actually did not have this problem when running CodeIgniter 4 locally on my computer using the built in spark server. The database driver is MySQLi and database is MySQL through phpMyAdmin.

Update: I notice when looking at the $_SERVER section for the exception, the 'database.default.DBPrefix' is still set to m8, even though I've left that field blank in the Database config file. I changed it to blank because that was the default value set after I installed codeigniter 4 to the server, and I noticed it wasn't set in my local installation so I suspected that could be the issue, but it still persists. So now I'm wondering if I have to somehow restart the server so the change is reflected.

Any help is appreciated.
Reply
#2

(01-19-2023, 11:34 AM)Vurnex Wrote: Update: I notice when looking at the $_SERVER section for the exception, the 'database.default.DBPrefix' is still set to m8, even though I've left that field blank in the Database config file. I changed it to blank because that was the default value set after I installed codeigniter 4 to the server, and I noticed it wasn't set in my local installation so I suspected that could be the issue, but it still persists. So now I'm wondering if I have to somehow restart the server so the change is reflected.

Check your .env file
https://codeigniter4.github.io/CodeIgnit...odeigniter
or environment variables if you can set them on your server/control panel.

If there are environment variables for config items, it will be loaded automatically.
See https://codeigniter4.github.io/CodeIgnit...-variables
Reply
#3

Such a simple fix...thanks so much. The issue is resolved now.
Reply
#4

Please edit your Topic Title and add [SOLVED] to it. Thank you.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB