Beispiel #1
0
 /**
  * {@inheritdoc}
  */
 public function execute($params = null)
 {
     if ($params) {
         $hasZeroIndex = array_key_exists(0, $params);
         foreach ($params as $key => $val) {
             $key = $hasZeroIndex && is_numeric($key) ? $key + 1 : $key;
             $this->bindValue($key, $val);
         }
     }
     if (!$this->stmt) {
         $stmt = sqlsrv_prepare($this->conn, $this->sql, $this->params);
         if (!$stmt) {
             throw SQLSrvException::fromSqlSrvErrors();
         }
         $this->stmt = $stmt;
     }
     if (!sqlsrv_execute($this->stmt)) {
         throw SQLSrvException::fromSqlSrvErrors();
     }
     if ($this->lastInsertId) {
         sqlsrv_next_result($this->stmt);
         sqlsrv_fetch($this->stmt);
         $this->lastInsertId->setId(sqlsrv_get_field($this->stmt, 0));
     }
 }
Beispiel #2
0
 /**
  * {@inheritDoc}
  */
 public function lastInsertId($name = null)
 {
     if ($name !== null) {
         $sql = "SELECT IDENT_CURRENT(" . $this->quote($name) . ") AS LastInsertId";
         $stmt = $this->prepare($sql);
         $stmt->execute();
         return $stmt->fetchColumn();
     }
     return $this->lastInsertId->getId();
 }