You are here

function _demo_get_fields in Demonstration site (Sandbox / Snapshot) 5

Same name and namespace in other branches
  1. 8 demo.module \_demo_get_fields()
  2. 6 database_mysql_dump.inc \_demo_get_fields()
  3. 7 database_mysql_dump.inc \_demo_get_fields()

Return table fields and their properties.

1 call to _demo_get_fields()
_demo_dump_table_data in ./database_mysql_dump.inc
Dump table data.

File

./database_mysql_dump.inc, line 167

Code

function _demo_get_fields($result) {
  $fields = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
      $num_fields = mysql_num_fields($result);
      for ($i = 0; $i < $num_fields; $i++) {
        $meta = mysql_fetch_field($result, $i);

        // Enhance field definition with custom properties.
        $meta->timestamp = (int) ($meta->type == 'timestamp');
        $flags = mysql_field_flags($result, $i);
        $meta->binary = (int) (stristr($flags, 'binary') !== FALSE);
        $fields[] = $meta;
      }
      break;
    case 'mysqli':
      while ($meta = mysqli_fetch_field($result)) {

        // Enhance the field definition for mysql-extension compatibilty.
        $meta->numeric = (int) (bool) ($meta->flags & MYSQLI_NUM_FLAG);
        $meta->blob = (int) (bool) ($meta->flags & MYSQLI_BLOB_FLAG);

        // Add custom properties.
        $meta->timestamp = (int) ($meta->type == MYSQLI_TYPE_TIMESTAMP);
        $meta->binary = (int) (bool) ($meta->flags & MYSQLI_BINARY_FLAG);
        $fields[] = $meta;
      }
      break;
  }
  return $fields;
}