我想在where子句中等于两个表列值(动态),我的代码是这样的
array('table1.column1' => 'table2.column2')
它像这样显示 SQL 查询
where `table1`.`column1` = 'table2.column2'
但我想喜欢这个:
where `table1`.`column1` = `table2`.`column2`
我只想将逗号"'"改为这个"'",请帮帮我吗?
提前谢谢。
如果要
转义引号,可以将第三个参数设置为 false:
->where('table1.column1', 'table2.column2', false)
只需简单地将字符串用于 where 条件,例如
$where="table1.column1 = table2.column2";
$this->db->where($where);
$where = "name='Joe' AND status='boss' OR status='active'";
$this->db->where($where);
Reference link:
https://ellislab.com/codeigniter/user-guide/database/active_record.html#select
Custom string:
You can write your own clauses manually:
您还可以更明确地使用字符串
->where(array("'table1'.'column1'" => "'table2'.'column2'"));