Exemplo n.º 1
0
 /**
  * 批量写入数据 
  * 
  * @param array   $fields         字段定义
  * @param array   $datas          数据(需要和字段定义个数相同)
  * @param boolean $ignore         是否为忽略写入(默认否)
  * @param string  $show_row_count 是否需要返回行数(默认不返回)
  * 
  * @return mixed 若$show_row_count为true,则返加行数,否则无异常返回true
  */
 public function insertBatch(array $fields, array $datas, $ignore = false, $show_row_count = false)
 {
     $sql = 'INSERT';
     $ignore && ($sql .= ' IGNORE');
     $sql .= " INTO `{$this->_table}` (";
     //拼KEY
     foreach ($fields as $value) {
         $sql .= "`{$value}`,";
     }
     $sql = rtrim($sql, ',') . ') VALUES';
     //接VALUES
     $sql_params = array();
     foreach ($datas as $values) {
         $sql .= '(' . self::repeatParams($values) . '),';
         $sql_params = array_merge($sql_params, $values);
     }
     $sql = rtrim($sql, ',');
     if ($show_row_count) {
         return $this->_db->exec($sql, $sql_params);
     } else {
         $this->_db->executeSql($sql, $sql_params);
         return true;
     }
 }
Exemplo n.º 2
0
 /**
  * Deletes this model from table
  *
  * @return boolean
  */
 public function delete()
 {
     if ($this->id and $this->beforeDelete()) {
         $sql = Mysql::prepareDelete(static::getTable(), ['id' => $this->id]);
         if (Mysql::exec($sql)) {
             return $this->afterDelete();
         }
     }
     return false;
 }