CI_DB_query_builder::insert PHP Method

insert() public method

Compiles an insert string and runs the query
public insert ( $table = '', $set = NULL, boolean $escape = NULL ) : boolean
$escape boolean Whether to escape values and identifiers
return boolean TRUE on success, FALSE on failure
    public function insert($table = '', $set = NULL, $escape = NULL)
    {
        if ($set !== NULL) {
            $this->set($set, '', $escape);
        }
        if ($this->_validate_insert($table) === FALSE) {
            return FALSE;
        }
        $sql = $this->_insert($this->protect_identifiers($this->qb_from[0], TRUE, $escape, FALSE), array_keys($this->qb_set), array_values($this->qb_set));
        $this->_reset_write();
        return $this->query($sql);
    }

Usage Example

示例#1
0
 public function add($data)
 {
     $data = $this->check_fields($data);
     if (array_key_exists('created', $this->table_fields)) {
         $data['created'] = date('Y-m-d H:i:s');
     }
     $this->db->insert($this->table, $data);
     $CR = new CI_DB_result($this->db);
     return mysqli_insert_id($CR->conn_id);
 }
All Usage Examples Of CI_DB_query_builder::insert