See also: MySQL Insert Statement http://dev.mysql.com/doc/refman/5.7/en/insert.html
Inheritance: implements SQLBuilder\ToSqlInterface, use trait SQLBuilder\Universal\Traits\OptionTrait, use trait SQLBuilder\MySQL\Traits\PartitionTrait
コード例 #1
0
ファイル: InsertQueryTest.php プロジェクト: c9s/sqlbuilder
 public function testInsertWithQuestionMark()
 {
     $driver = new MySQLDriver();
     $driver->setQMarkParamMarker();
     $args = new ArgumentArray();
     $query = new InsertQuery();
     $query->option('LOW_PRIORITY', 'IGNORE');
     $query->insert(['name' => new Bind('name', 'John'), 'confirmed' => new Bind('confirmed', true)])->into('users');
     $query->returning('id');
     $sql = $query->toSql($driver, $args);
     $this->assertEquals('INSERT LOW_PRIORITY IGNORE INTO users (name,confirmed) VALUES (?,?)', $sql);
 }
コード例 #2
0
ファイル: BaseModel.php プロジェクト: appleboy/LazyRecord
 /**
  * Simply create record without validation and triggers.
  *
  * @param array $args
  */
 public function rawCreate(array $args)
 {
     $dsId = $this->writeSourceId;
     $conn = $this->getWriteConnection();
     $k = static::PRIMARY_KEY;
     $driver = $this->getWriteQueryDriver();
     $query = new InsertQuery();
     $query->insert($args);
     $query->into($this->table);
     $query->returning($k);
     $arguments = new ArgumentArray();
     $sql = $query->toSql($driver, $arguments);
     $stm = $conn->prepare($sql);
     $stm->execute($arguments->toArray());
     $pkId = null;
     if ($driver instanceof PDOPgSQLDriver) {
         $pkId = $stm->fetchColumn();
     } else {
         // lastInsertId is supported in SQLite and MySQL
         $pkId = $conn->lastInsertId();
     }
     $this->_data = $args;
     $this->_data[$k] = $pkId;
     return $this->reportSuccess('Create success', array('sql' => $sql, 'type' => Result::TYPE_CREATE));
 }
コード例 #3
0
ファイル: BaseModel.php プロジェクト: azole/LazyRecord
 /**
  * Simply create record without validation and triggers.
  *
  * @param array $args
  */
 public function rawCreate(array $args)
 {
     $dsId = $this->getWriteSourceId();
     $conn = $this->getConnection($dsId);
     $k = static::primary_key;
     $driver = $conn->createQueryDriver();
     $query = new InsertQuery();
     $query->insert($args);
     $query->into($this->getTable());
     $query->returning($k);
     $arguments = new ArgumentArray();
     $sql = $query->toSql($driver, $arguments);
     $stm = $this->dbPrepareAndExecute($conn, $sql, $arguments->toArray());
     $pkId = null;
     if ($driver instanceof PDOPgSQLDriver) {
         $pkId = $stm->fetchColumn();
     } else {
         // lastInsertId is supported in SQLite and MySQL
         $pkId = $conn->lastInsertId();
     }
     $this->_data = $args;
     $this->_data[$k] = $pkId;
     return $this->reportSuccess('Create success', array('sql' => $sql));
 }