dqnrk44682
2017-12-19 10:59
浏览 101
已采纳

使用CodeIgniter上的重复值查询数据绑定

Suppose I have a query like that:

SELECT *
FROM table
WHERE table.a = 23
AND table.b = 23
AND (23 - table.c)/23 > 0.2

This may not have any sense because it is just an example. My real query is much bigger than this one. As you can see, all the values to be binded are equals.

So, how can I use CodeIgniter data binding for this query if all ? are the same data?

Repeting values like this on an array looks strange on code:

$sql = "SELECT *"
       ." FROM table"
       ." WHERE table.a = ?"
       ." AND table.b = ?"
       ." AND (? - table.c)/? > 0.2";

$this->db->query($sql, array(23, 23, 23, 23);

图片转代码服务由CSDN问答提供 功能建议

假设我有这样的查询:</ p>

  SELECT *  
FROM表
WHERE table.a = 23 
AND table.b = 23 
AND(23  -  table.c)/ 23&gt;  0.2 
 </ code> </ pre> 
 
 

这可能没有任何意义,因为它只是一个例子。 我的真实查询比这个查询大得多。 如您所见,要绑定的所有值都是等于。</ p>

因此,如果所有?</ code>都相同,如何对此查询使用CodeIgniter数据绑定 数据?</ p>

在数组上重复这样的值在代码上看起来很奇怪:</ p>

  $ sql =“SELECT *”
。“  FROM表“
。”WHERE table.a =?“
。”AND table.b =?“
。”AND(? -  table.c)/?&gt; 0.2“; 
 
 $ this this  - &gt; db-&gt;查询($ sql,array(23,23,23,23); 
 </ code> </ pre> 
 </ div>

1条回答 默认 最新

相关推荐 更多相似问题