在codeigniter字符中查询变化

时间:2014-03-03 04:23:42

标签: php codeigniter postgresql

如何在codeigniter中做到这一点?

$this->db->query('UPDATE "table1" SET tech_voc=(select tech_voc from table1 where "tableID"='table1' AND psced_id="62") WHERE "tableID"="table1-A" AND major_id=1;');  

我也做了

select tech_voc from table1 where "tableID"="table1-A";     //w qoutes
select tech_voc from table1 where "tableID"=table1-A;       //w/o quotes

但仍然有错误。它说

错误:运算符不存在:字符变化。是的,我知道

但是当我尝试使用postgreSQL时

select tech_voc from table1 where "tableID"='table1-A'; // is correct
编辑------- @ Nouphal.M 这是ERROR消息:

错误:“" LINE 1: UPDATE table1”或附近的语法错误SET tech_voc =(^

UPDATE table1 SET tech_voc =(SELECT tech_voc FROM table1 WHERE tableID ='table1'AND psced_id = 62)WHERE tableID ='table1-A'AND_id = 1)< / p>

编辑------- @tomexsans TESTING

我尝试了你说的话,它给出了服务器错误。

这是我尝试测试的代码。

$sql ="SELECT tech_voc FROM table1 WHERE `tableID`= ? AND `psced_id` = ?"; 
$this->db->query($sql,array['table1','62']);

2 个答案:

答案 0 :(得分:0)

它在SQL中是错误的: 从table1中选择tech_voc,其中“tableID”='table1-A';

请尝试:

select tech_voc from table1 where tableID='table1-A'; 

您的最终查询如下:

    $this->db->query("UPDATE table1 SET tech_voc=(select tech_voc from table1 where 
tableID='table1' AND psced_id='62') WHERE tableID='table1-A' AND major_id=1;"); 

答案 1 :(得分:0)

我所做的是在数据库中将tableID更改为table_id。 PostregreSQL区分大小写,在Codeigniter中很难使用它。

所以这是我的最终代码:

$this->db->query("UPDATE table1 SET tech_voc=(select tech_voc from table1 where table_id='table1' AND psced_id='62') 
WHERE table_id='table1-A' AND major_id=1;");

感谢所有分享他们想法的人。

相关问题