php - 针对这种特殊情况执行sql操作

标签 php mysql sql codeigniter

先生,

我遇到了一个问题,如下所示: 我想对 $this->db->select('*')->from('table'); 的输出执行 where 操作仅当 cond1 满足时

 $result = $this->db->select('*')->from('table');
 if(cond1)
 {
  I want to perform $result->where(); operation
 }

是否可能,那么具体的语法是什么

最佳答案

尝试这样的事情:

$this->db->select('*');
$this->db->from('table');
if ($cond1)
    $this->db->where(...)

$query = $this->db->get();

关于php - 针对这种特殊情况执行sql操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17069472/

相关文章:

php - 使用 GROUP SEPARATOR 的 Explode() 函数

mysql - MYSQL数据库建模器在图 View 中显示参照完整性

php - 在保存到数据库之前处理 Javascript

java - 声明已结束,没有进一步的内部信息

php - 默认情况下,在商店页面上随机显示 WooCommerce 产品

php - 使用斜线后 URL 中的文本作为参数 - htaccess

javascript - 如何将变量值从 JavaScript 传递到 PHP

mysql - 我们如何在sequelize中关闭数据库 `connection`

mysql - 更新和插入,重复键

mysql - 在 MariaDB 5.5.52 中使用生成的列