You are here

function DB_mysql::createSequence in Flickr API 5

Creates a new sequence

DB_mysql::nextID(), DB_mysql::dropSequence()

Parameters

string $seq_name name of the new sequence:

Return value

int DB_OK on success. A DB_Error object on failure.

Overrides DB_common::createSequence

See also

DB_common::createSequence(), DB_common::getSequenceName(),

1 call to DB_mysql::createSequence()
DB_mysql::nextId in phpFlickr/PEAR/DB/mysql.php
Returns the next free id in a sequence

File

phpFlickr/PEAR/DB/mysql.php, line 662

Class

DB_mysql
The methods PEAR DB uses to interact with PHP's mysql extension for interacting with MySQL databases

Code

function createSequence($seq_name) {
  $seqname = $this
    ->getSequenceName($seq_name);
  $res = $this
    ->query('CREATE TABLE ' . $seqname . ' (id INTEGER UNSIGNED AUTO_INCREMENT NOT NULL,' . ' PRIMARY KEY(id))');
  if (DB::isError($res)) {
    return $res;
  }

  // insert yields value 1, nextId call will generate ID 2
  $res = $this
    ->query("INSERT INTO {$seqname} (id) VALUES (0)");
  if (DB::isError($res)) {
    return $res;
  }

  // so reset to zero
  return $this
    ->query("UPDATE {$seqname} SET id = 0");
}