CodeIgniter Forums
Round brackets issue in Codeigniter - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: Issues (https://forum.codeigniter.com/forumdisplay.php?fid=19)
+--- Thread: Round brackets issue in Codeigniter (/showthread.php?tid=70224)



Round brackets issue in Codeigniter - kalyanbl - 03-10-2018

Hi,

I am working on Codeigniter project, I need to migrate whole database MySQL to SQL server, for that I am getting an issue in select query, I can see in SQL server round brackets are not supported around the table name, here is my Codeigniter query

$this->db->_protect_identifiers=false;
$this->db->select('*')->from('tb_card',false);
$this->db->where('company_id',$this->company_id,FALSE)->get()->row_array();
This select query generates below query

SELECT * FROM (tb_card) WHERE company_id = 27

You can see there are round brackets around the table name, I want to remove this, can anyone please help me to resolve this issue?

Thank you


RE: Round brackets issue in Codeigniter - InsiteFX - 03-10-2018

And what do get doing it this way?

PHP Code:
$this->db->_protect_identifiers false;

$query $this->db->where('company_id'$this->company_idFALSE)
 
   ->get('tb_card')
 
   ->row_array(); 

Do you get the same output?

If so you could use the database query method and build your own sql select statement.


RE: Round brackets issue in Codeigniter - jamesmillere - 01-19-2023

The issue you are facing is because the Codeigniter query builder is adding round brackets around the table name by default. To prevent this, you can set the "_protect_identifiers" property to false before running the query. Additionally, you can pass "false" as the second parameter to the "from()" method to prevent the table name from being enclosed in brackets. The modified query would look like this:

$this->db->_protect_identifiers = false;
$this->db->select('*')->from('tb_card', false);
$this->db->where('company_id', $this->company_id, FALSE)->get()->row_array();

This should generate the correct query for MySQL and SQL Server.