Airship\Engine\Contract\DBInterface::insert PHP Method

insert() public method

Insert a new row to a table in a database.
public insert ( string $table, array $map )
$table string - table name
$map array - associative array of which values should be assigned to each field
    public function insert(string $table, array $map);

Usage Example

示例#1
0
 /**
  * Create, store, and return a token for long-term authentication
  * 
  * @param int $userId
  * @return string (to store in a cookie, for example)
  */
 public function createAuthToken(int $userId) : string
 {
     $f = $this->tableConfig['fields']['longterm'];
     $selector = \random_bytes(self::SELECTOR_BYTES);
     $validator = \random_bytes(self::VALIDATOR_BYTES);
     $this->db->insert($this->tableConfig['table']['longterm'], [$f['userid'] => $userId, $f['selector'] => Base64::encode($selector), $f['validator'] => CryptoUtil::hash($validator)]);
     return Base64::encode($selector . $validator);
 }