查询字段为空

时间:2011-04-01 04:21:28

标签: php mysql

以下功能的逻辑是什么?

function check_empty($field){
  $this->_params();
  $db = $this->getDb();
  $milestone = $db->select()
    ->from('milestone')
    ->where("$field IN ('')")
    ->where("name = ?", $this->milestone['name']);

  $milestone_stmt = $db->query($milestone);
  echo $milestone->__toString();
  $milestone_result = $milestone_stmt->fetchAll();

  if(count($milestone_result) > 0) {
    return true;
  } else {
    return false;
  }
}

这是用于检查字段是否为空的函数。如果该字段最初是字段并使用表单中删除的内容进行更新,则其他函数应插入表单 但它没有插入。

1 个答案:

答案 0 :(得分:1)

如果查询无法匹配任何行,则返回true,否则返回false:

function check_empty($field) {
    $this->_params();
    $db = $this->getDb();
    $milestone = $db->select()
                    ->from('milestone')
                    ->where("$field = ''")
                    ->where("name = ?", $this->milestone['name']);
    $milestone_stmt = $db->query($milestone);

    //No query results means the field is not empty.
    return $milestone_stmt === false;
}