You are here

function DB_mysql::tableInfo in Flickr API 5

Returns information about a table or a result set

Parameters

object|string $result DB_result object from a query or a: string containing the name of a table. While this also accepts a query result resource identifier, this behavior is deprecated.

int $mode a valid tableInfo mode:

Return value

array an associative array with the information requested. A DB_Error object on failure.

Overrides DB_common::tableInfo

See also

DB_common::tableInfo()

File

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

Class

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

Code

function tableInfo($result, $mode = null) {
  if (is_string($result)) {

    /*
     * Probably received a table name.
     * Create a result resource identifier.
     */
    $id = @mysql_list_fields($this->dsn['database'], $result, $this->connection);
    $got_string = true;
  }
  elseif (isset($result->result)) {

    /*
     * Probably received a result object.
     * Extract the result resource identifier.
     */
    $id = $result->result;
    $got_string = false;
  }
  else {

    /*
     * Probably received a result resource identifier.
     * Copy it.
     * Deprecated.  Here for compatibility only.
     */
    $id = $result;
    $got_string = false;
  }
  if (!is_resource($id)) {
    return $this
      ->mysqlRaiseError(DB_ERROR_NEED_MORE_DATA);
  }
  if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE) {
    $case_func = 'strtolower';
  }
  else {
    $case_func = 'strval';
  }
  $count = @mysql_num_fields($id);
  $res = array();
  if ($mode) {
    $res['num_fields'] = $count;
  }
  for ($i = 0; $i < $count; $i++) {
    $res[$i] = array(
      'table' => $case_func(@mysql_field_table($id, $i)),
      'name' => $case_func(@mysql_field_name($id, $i)),
      'type' => @mysql_field_type($id, $i),
      'len' => @mysql_field_len($id, $i),
      'flags' => @mysql_field_flags($id, $i),
    );
    if ($mode & DB_TABLEINFO_ORDER) {
      $res['order'][$res[$i]['name']] = $i;
    }
    if ($mode & DB_TABLEINFO_ORDERTABLE) {
      $res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
    }
  }

  // free the result only if we were called on a table
  if ($got_string) {
    @mysql_free_result($id);
  }
  return $res;
}