CodeIgniter Forums
Question [DB Query Builder] - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Question [DB Query Builder] (/showthread.php?tid=62912)



Question [DB Query Builder] - -V1cu- - 09-07-2015

Hello guys,

I am a bit confused of some functions from the library DB Query Builder.

I tried to use db->from, db->join in this way:

PHP Code:
$this->db->from('table t');
$this->db->join('table2 t2''condition''left'); 

but when i run the query i saw, that this functions add to the table '`' before and after, and the result is something like:

PHP Code:
FROM `table` `t`
LEFT JOIN `table2` `t2ON condition 

Is totally wrong... How i can use this function to get normal results like: `table` t and `table2` t2, and btw this happens and on the select function when i use: t.`column`, it makes `t`.`column`?

Thanks.


RE: Question [DB Query Builder] - ivantcholakov - 09-07-2015

Code:
$this->db->from('table AS t');
$this->db->join('table2 AS t2', 'condition', 'left');



RE: Question [DB Query Builder] - -V1cu- - 09-07-2015

(09-07-2015, 11:47 AM)ivantcholakov Wrote:
Code:
$this->db->from('table AS t');
$this->db->join('table2 AS t2', 'condition', 'left');


I tried... Result is the same.


RE: Question [DB Query Builder] - ivantcholakov - 09-07-2015

Maybe the fake 'condition' breaks the query builder. On current 3.0.2-dev code I tested this:

Code:
$this->db->from('table AS t');
$this->db->join('table2 AS t2', 't.id = t2.t_id', 'left');
echo $this->db->get_compiled_select();

And here is the produced SQL:

Code:
SELECT *
FROM `table` AS `t`
LEFT JOIN `table2` AS `t2` ON `t`.`id` = `t2`.`t_id`



RE: Question [DB Query Builder] - Narf - 09-08-2015

(09-07-2015, 08:49 AM)-V1cu- Wrote:
PHP Code:
FROM `table` `t`
LEFT JOIN `table2` `t2ON condition 

Is totally wrong...

How's escaping the aliases totally wrong?


RE: Question [DB Query Builder] - -V1cu- - 09-08-2015

(09-08-2015, 01:04 AM)Narf Wrote:
(09-07-2015, 08:49 AM)-V1cu- Wrote:
PHP Code:
FROM `table` `t`
LEFT JOIN `table2` `t2ON condition 

Is totally wrong...

How's escaping the aliases totally wrong?


My bad, i read the documentation and looked on the source library. Solved, thanks!