CodeIgniter Forums
dbprefix([$table = '']) - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: CodeIgniter 3.x (https://forum.codeigniter.com/forumdisplay.php?fid=17)
+--- Thread: dbprefix([$table = '']) (/showthread.php?tid=63389)



dbprefix([$table = '']) - ComputingFroggy - 10-25-2015

Hi,

reading the manual on dbprefix, I would have thought to get the prefix used one could write :
Code:
    $thePrefix=$this->db->dbprefix('');

However this fires up an error asking for a table name.
Considering the documentation states the table name is optional (and empty), I thought I could get the prefix that way.

Instead, I am doing:
Code:
        $thePrefix=substr($this->db->dbprefix('X'), 0, -1);
Not particularly elegant, but that works.

I would think either the documentation or the method behaviour should be changed.


Cheers,
L@u


RE: dbprefix([$table = '']) - rtorralba - 10-25-2015

(10-25-2015, 07:59 AM)ComputingFroggy Wrote: Hi,

reading the manual on dbprefix, I would have thought to get the prefix used one could write :

Code:
    $thePrefix=$this->db->dbprefix('');

However this fires up an error asking for a table name.
Considering the documentation states the table name is optional (and empty), I thought I could get the prefix that way.

Instead, I am doing:

Code:
        $thePrefix=substr($this->db->dbprefix('X'), 0, -1);
Not particularly elegant, but that works.

I would think either the documentation or the method behaviour should be changed.


Cheers,
L@u

I think you can retrieve it with:
  • $this->db->dbprefix; // Making before $this->load->database();
  • $this->config->item('dbprefix', 'database');



RE: dbprefix([$table = '']) - PaulD - 10-25-2015

Yes, the documentation is quite clear that:

Code:
$this->db->dbprefix('');

is for adding the default prefix to a table name, so a table name is required. http://www.codeigniter.com/user_guide/database/query_builder.html?#CI_DB_query_builder::dbprefix



And rtorralba is quite right, I just did a test to get the prefix with

Code:
$this->db->dbprefix;

And it worked fine.

Best wishes,

Paul