Jump to content


Code Igniter database prexif issue

database prefix codeigniter

  • Please log in to reply
No replies to this topic

#1 cegroj

cegroj

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 30 June 2017 - 01: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.







Also tagged with one or more of these keywords: database, prefix, codeigniter

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users