Db::insert PHP Method

insert() public method

插入记录
public insert ( mixed $data, array $options = [] ) : false | integer
$data mixed 数据
$options array 参数表达式
return false | integer | integer
    public function insert($data, $options = array())
    {
        foreach ($data as $key => $val) {
            $value = $this->parseValue($val);
            if (is_scalar($value)) {
                // 过滤非标量数据
                $values[] = $value;
                $fields[] = $this->addSpecialChar($key);
            }
        }
        $sql = 'INSERT INTO ' . $this->parseTable($options['table']) . ' (' . implode(',', $fields) . ') VALUES (' . implode(',', $values) . ')';
        $sql .= $this->parseLock(isset($options['lock']) ? $options['lock'] : false);
        return $this->execute($sql);
    }

Usage Example

Example #1
0
 public function save()
 {
     $query = "INSERT INTO miembros values (null,'" . $this->getNombre() . "',null,'" . $this->getEmail() . "')";
     $conn = new Db("localhost", "root", "benjamin13");
     $conn->connect();
     $conn->insert($query, "conquistadores");
 }
All Usage Examples Of Db::insert