静态插入

@param string $table
@param array  $data

@return int|string
9723
public static function insert($table, $data) {
        $insert = Insert::table($table);
        foreach ($data as $field => $value) {
            $insert->set($field, $value);
        }
        return $insert->excuse();
    }
166757
public function update($table, array $data, $conditions)
    {
        $nameFields = array_keys($data);
        $preparedValues = $this->prepareValues($data);
        $queryString = "UPDATE {$table} SET ";

        $fNumber = 0;
        foreach ($preparedValues as $key => $value) {
            unset($value);
            $queryString .= "{$nameFields[$fNumber]} = {$key}, ";
            $fNumber++;
        }

        $queryString = preg_replace('/,\ $/', ' ', $queryString);
        $queryString .= "WHERE {$conditions};";

        $this->query($queryString, $preparedValues);

        return $this->getAffectedRows();
    }
866022
public function insert($table, $data) {
        if (!$this->validateTableAndCol($table, array_keys($data))) {
            throw new \InvalidArgumentException ('Table or coloumn information is incorrect acorrding to the contract');
        }

        if ($data && !$this->validateBind($table, $data)) {
            throw new \InvalidArgumentException ('Input data is incorrect acorrding to the contract');
        }

        $result = $this->db_adapter->insert($table, $data);
        if (!$result) {
            throw new \InvalidArgumentException ($this->db_adapter->getLastError());
        }   

        return $result;
    }
11396
public function insert($table = '', $data = array())
    {
        if (empty($data)) {
            die('数据不能为空！');
        }

        //字段名处理
        foreach ($data as $k => $v) {
            $fields[] = $k;
            $values[] = $v;
            $this->bindParam($k, $v);
        }

        //insert的sql语句处理
        $sql = 'INSERT INTO '.$table.' ( '.implode(',', $fields)
            .') VALUES (';
        foreach ($fields as $k => $v) {
            $sql.=':'.$v.',';
        }
        $sql = rtrim($sql, ',');
        $sql .= ')';
        echo '<br/>'.$sql.'<br/>';

        return $this->execute($sql);
    }
445935
public function insert($table, $data)
    {
        // empty data
        if (empty($data))
            Throw new \ErrorException("SQL Error: Can't insert empty data.");

        // prepare data
        $cols = ($values = array());
        foreach ($data as $column => $value) {
            $cols[] = '`' . $column . '`';
            $values[] = "'" . $this->escape($value) . "'";
        }

        // build query string...
        $query_string = 'INSERT INTO `' . $this->getPrefix() . $table . '` (' . implode(',', $cols) . ') VALUES (' . implode(',', $values) . ')';

        return $this->doQuery($query_string); // ... and execute
    }
612242
public function update($table, array $data)
    {
        $conditions = array();

        foreach ($data as $key => $value) {
            // Wrap column names into back-ticks
            $conditions[] = sprintf('%s = %s', $this->quote($key), $value);
        }

        $query = sprintf('UPDATE %s SET %s', $this->quote($table), implode(', ', $conditions));
        $this->append($query);

        return $this;
    }
889601
public function GetDelete($Table, $Where, &$Data) {
      if (is_array($Data)) {
         // Grab the records.
         $Result = $this->SQL->GetWhere($Table, $Where)->ResultArray();
         
         if (empty($Result))
            return;
         
         // Put the records in the result array.
         if (isset($Data[$Table])) {
            $Data[$Table] = array_merge($Data[$Table], $Result);
         } else {
            $Data[$Table] = $Result;
         }
      }
      
      $this->SQL->Delete($Table, $Where);
   }
892046
public function getColumns($table){
        $sql = 'SHOW COLUMNS FROM '. $this->formatKey($table);
        $result = $this->query($sql);
        if ($result === false) return array();
        $array = array();
        
        while ($tmp = mysqli_fetch_array($result, MYSQLI_ASSOC)){
            // $tmp['Type'] 格式为 varchar(30), 可解析出 data_type, data_length
            preg_match('/([^\(]+)\(?(\d*)\)?/i', $tmp['Type'], $matches);
            $data_type = $matches[1];
            $data_length = $matches[2];
            $array[$tmp['Field']] = array(
                'name'      => $tmp['Field'],
                'type'      => $data_type,
                'length'    => $data_length,
                'null'      => $tmp['Null'],
                'primary'   => (strtolower($tmp['Key']) == 'pri'),
                'default'   => $tmp['Default'],
                'auto_increment' => (strtolower($tmp['Extra']) == 'auto_increment'),
            );
        }
        return $array;
    }
800675
public function update($table, array $data = [])
    {
        /**
         * Flatten data for possible multivalued values like geometric POINT or so.
         */
        $cache = $this->repository->getCache();
        foreach ($data as $key => &$val) {
            if (is_array($val)) {
                if ($cache->tableHasField($table, $key) && $cache->getField($key, $table)['type'] == 'point') {
                    $val = new Raw('GeomFromText(\'POINT(' . (float)$val[0] . ' ' . (float)$val[1] . ')\')');
                }
            }
        }

        /**
         * We will update record in $table with $data ...
         */
        $query = (new Update())->setTable($table)->setSet($data);

        /**
         * ... add primary key condition ...
         */
        $query->primaryWhere($this->entity, $data, $table);

        /**
         * ... prepare query ...
         */
        $prepare = $this->repository->prepareQuery($query, null);

        /**
         * ... and execute it.
         */
        $this->repository->executePrepared($prepare);

        /**
         * Return number of updated records.
         */
        return $prepare->rowCount();
    }
448960
public function insertPDO($table, array $data = array())
    {
        if (count($data) === 0) {
            return false;
        }
        $q = "INSERT INTO `$table` ";
        $v = '';
        $n = '';

        foreach ($data as $key => $val) {
            $n .= "`$key`, ";
            if (strtolower($val) === 'now()') {
                $v .= 'NOW(), ';
                unset($data[$key]);
            } else {
                $v .= '?, ';
            }
        }
        $q .= '(' . rtrim($n, ', ') . ') VALUES (' . rtrim($v, ', ') . ');';
        try {
            $this->_queryId = self::$_linkId->prepare($q);

            $i = 1;
            foreach ($data as $key => $val) {
                $type = $this->getPDOConstantType($val);
                $this->_queryId->bindValue($i, $val, $type);
                ++$i;
            }
            $this->_queryId->execute();
            return self::$_linkId->lastInsertId();
        } catch (PDOException $e) {
            $this->_error = $e->getMessage();
            return false;
        }
    }
767368
public function deleteFrom(string $table, array $where): int
    {
        $delete = new Delete($this->options);
        $sqlParams = $delete->buildQuery($table, $where);
        return $this->query($sqlParams->getSql(), $sqlParams->getParams())->getAffected();
    }
1315110
public function insert($table, array $data = [])
    {
        /**
         * Flatten data for possible multivalued values like geometric POINT or so.
         */
        $cache = $this->repository->getCache();
        foreach ($data as $key => &$val) {
            if (is_array($val)) {
                if ($cache->tableHasField($table, $key) && $cache->getField($key, $table)['type'] == 'point') {
                    $x = ($val['x'] ?? $val[0]) ?? 0;
                    $y = ($val['y'] ?? $val[1]) ?? 0;
                    $val = new Raw('GeomFromText(\'POINT(' . $x . ' ' . $y . ')\')');
                }
            }
        }

        /**
         * We will insert $data into $table ...
         */
        $query = (new Insert())->table($table)->setInsert($data);

        /**
         * ... prepare query ...
         */
        $prepare = $this->repository->prepareQuery($query);

        /**
         * ... execute it ...
         */
        $this->repository->executePrepared($prepare);

        /**
         * ... and return inserted ID.
         */
        return $this->repository->getConnection()->lastInsertId();
    }
906414
public function insert($table, array $data)
    {
        // Prepare
        $columnPart = "";
        $valuePart = "";

        // Loop the data
        foreach ($data as $column => $value) {
            $columnPart .= "`$column`, ";
            $valuePart .= "?, ";
        }

        // Remove last commas
        $columnPart = substr($columnPart, 0, -2);
        $valuePart = substr($valuePart, 0, -2);

        $query = "INSERT INTO `$table` ($columnPart) VALUES ($valuePart)";


        // Prepare and bind
        $statement = $this->prepare($query);

        $idx = 0;
        foreach ($data as $key => $value) {
            $statement->bindValue(($idx+1), $value, Database::typeOfValue($value));
            $idx++;
        }

        // Execute and return the execute returning value.
        return $statement->execute();
    }
511371
public function setData(string $table, $data){
            
            $file = $this->base . '/' . $table . '.json';
            if(file_exists($file)){
                if(file_put_contents($file, json_encode($data))){
                    $status = true;
                }else{
                    $status = false;
                }
                return new \NonDB\Components\Status($status);
            }else{
                throw new \NonDB\Exceptions\DriverException('Table Not Exists.', 1002);
            }

        }
697815
protected function makeTable($table): ?Table
    {
        // 如果是字符串,那么应该是表名,创建表对象
        if (is_string($table)) {
            return table($table);
        }

        // 如果已经是表对象,返回
        if ($table instanceof Table) {
            return $table;
        }

        return null;
    }
1269767
public function create($table, $data){
        $keys = array_keys($data);
        $values = ':' . implode(',:', $keys);
        $keys = implode(',', $keys);
        return $this->query($this->set("INSERT INTO {$table} ({$keys}) VALUES({$values})", $data));
    }
1006801
public function update($table, $data, $where = '')
    {
        $fieldDetails = null;
        foreach ($data as $key => $value) {
            $fieldDetails .= "$key = :$key,";
        }
        $fieldDetails = rtrim($fieldDetails, ',');
        $query = "UPDATE $table SET $fieldDetails ".($where ? 'WHERE '.$where : '');
        $this->prepare($query);

        foreach ($data as $key => $value) {
            $this->bind(":$key", $value);
        }
        try {
            $this->execute();

            return true;
        } catch (PDOException $e) {
            echo $e->errorInfo[2];

            return false;
        }
    }