⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠


profile picture

Code Igniter database prexif issue


  • profile picture
  • Member

Posted 30 June 2017 - 13:46 PM

I have found that Crocerycrud does not work if you have a database prefix configured in your CodeIgniter project.


To fix this I have changed two lines in Grocery_crud_model.php.

Line 53 was

$select = "`{$this->table_name}`.*";

and now it is

$select = "{$this->table_name}.*";

without ` because the prefix was added before the first ` creating the sentence like prefix_`tablename`.* that leads to an SQL error.

And line 436 was

foreach($this->db->query("SHOW COLUMNS FROM `{$this->table_name}`")->result() as $db_field_type)

and now it is

foreach($this->db->query("SHOW COLUMNS FROM `{$this->db->dbprefix($this->table_name)}`")->result() as $db_field_type)

because without the prefix set in table_name the sentence fails. But if you try to add the prefix to table_name the error will show up later because of duplicated prefix in further sentences.


It looks like there are people that are using wrong table names (for example with whitespace or with dash!) and that's why was added the extra `.


This solution will work at the most of the cases but apparently it's needed to consider the users that are having wrong table names as there is no work-around for them! Usually for them it is just a pretty old database that they can't change.