/**
  *
  * Returns true if database table has rows where one of the given columns has one of the
  * given values.
  *
  * Example:
  *
  * <code>
  * if($this->hasRowWith(array("email" => "*****@*****.**"));
  * </code>
  *
  * @param array $columnsEqual
  *
  */
 public function hasRowWith(array $columnsEqual)
 {
     $sql = "select * from " . $this->parser->getTableName() . " where ";
     $sql .= implode("=? or ", array_keys($columnsEqual));
     $sql .= "=?";
     $row = $this->db->one($sql, array_values($columnsEqual));
     if (isset($row)) {
         return true;
     }
     return false;
 }
Example #2
0
 /**
  * Return "insert" SQL for the PDO adapter (prepared statements)
  * @param $data
  * @return mixed
  */
 private function getPDOInsert($data)
 {
     $table = $this->configParser->getTableName();
     if (!isset($data)) {
         $data = array($this->obj->configParser()->getIdField() => null);
     }
     $keys = array_keys($data);
     $sql = "insert into " . $table . "(" . implode(",", $keys) . ")";
     $values = implode(",", array_fill(0, count($keys), '?'));
     $sql .= "values(" . $values . ")";
     $sql = str_replace("'" . self::DELETED . "'", "null", $sql);
     return $sql;
 }