getInsertId() public method

public getInsertId ( ) : integer
return integer
Example #1
0
 public static function INSERT()
 {
     $sql = "INSERT INTO `DocumentPart` (`id`, `__timestamp__`, `__operation__`) VALUES (NULL, " . time() . ", 'INSERT')";
     $result = Database::sql($sql);
     $id = Database::getInsertId();
     return self::ROW($id);
 }
Example #2
0
 public static function add(&$data)
 {
     // Fields
     $SessionId = md5(microtime());
     $Ip = Database::escape($_SERVER['REMOTE_ADDR']);
     $UserAgent = Database::escape($_SERVER['HTTP_USER_AGENT']);
     $Created = time();
     $Data = Database::escape(serialize($data));
     $sql = "INSERT INTO `SystemSession` (`id`, `__timestamp__`, `__operation__`, `SessionId`, `Ip`, `UserAgent`, `Created`, `Data`) VALUES (NULL, " . time() . ", 'INSERT', '{$SessionId}', '{$Ip}', '{$UserAgent}', '{$Created}', '{$Data}')";
     // Run query
     $result = Database::sql($sql);
     $id = Database::getInsertId();
     return self::ROW($id);
 }
Example #3
0
 /**
  * save:
  * Through some internal logic, decides whether or not we need to perform an
  * INSERT or an UPDATE for this record, then performs that query.
  * This effectively saves the row to the database, regardless of its prior state.
  */
 function save($log = false)
 {
     $keyName = static::$_keyField;
     $keyValue = addslashes($this->getKeyValue());
     if (!$this->recordExists()) {
         $fields = $this->getInsertFieldList();
         $values = $this->getInsertValueList();
         if (!empty(static::$_insertTimestampField)) {
             // Since we want to keep track of INSERT timestamps, generate one.
             $fields .= ', `' . static::$_insertTimestampField . '`';
             $values .= ", NOW()";
         }
         if (!empty(static::$_updateTimestampField)) {
             // Since we want to keep track of UPDATE timestamps, generate one.
             $fields .= ', `' . static::$_updateTimestampField . '`';
             $values .= ", NOW()";
         }
         Database::query("INSERT INTO `" . static::$_tableName . "` ({$fields}) VALUES ({$values})", $log);
         $this->{$keyName} = Database::getInsertId();
         $this->_recordExists = true;
         if (!empty(static::$_cachePrefix)) {
             Cache::dirty(static::$_cachePrefix . $this->getId());
         }
         if (method_exists($this, 'recordSaved')) {
             $this->recordSaved();
         }
     } else {
         $fields = $this->getUpdateFieldList();
         if (!empty(static::$_updateTimestampField)) {
             // Since we want to keep track of UPDATE timestamps, generate one.
             if (!empty($fields)) {
                 $fields .= ', ';
             }
             $fields .= '`' . static::$_updateTimestampField . '` = NOW()';
         }
         Database::query("UPDATE `" . static::$_tableName . "` SET {$fields} WHERE `{$keyName}` = '{$keyValue}'", $log);
         $this->_recordExists = true;
         if (!empty(static::$_cachePrefix)) {
             Cache::dirty(static::$_cachePrefix . $this->getId());
         }
         if (method_exists($this, 'recordSaved')) {
             $this->recordSaved();
         }
     }
 }
Example #4
0
 private function insert()
 {
     if (in_array('add', static::$fields)) {
         $this->values['add'] = date('Y-m-d H:i:s');
     }
     $query = "INSERT INTO `" . static::TABLE . "`";
     $query .= ' (`' . implode('`, `', static::$fields) . '`) ';
     $query .= "VALUES ('" . implode("', '", $this->values) . "')";
     Database::query($query);
     $this->id = Database::getInsertId();
     if (!empty(static::$fieldsLang) && is_numeric($this->id_lang)) {
         if ($this->id_lang) {
             $query = "INSERT INTO `" . static::TABLE . "_lang` (`id_object`, `id_lang`, `";
             $query .= implode(`, `, static::$fieldsLang);
             $query .= "`) VALUES ({$this->id}, {$this->id_lang}, '";
             $query .= implode("', '", $this->valuesLang);
             $query .= "')";
             Database::query($query);
         } else {
             foreach (App::getLangs() as $lang) {
                 $lang = $lang->getId();
                 $query = "INSERT INTO `" . static::TABLE . "_lang` (`id_object`, `id_lang`, `";
                 $query .= implode('`, `', static::$fieldsLang);
                 $query .= "`) VALUES ({$this->id}, {$lang}, ";
                 foreach (static::$fieldsLang as $field) {
                     $query .= "'{$this->values_lang[$field][$lang]}', ";
                 }
                 $query = rtrim($query, ', ');
                 $query .= ")";
                 Database::query($query);
             }
         }
     }
 }