Exemplo n.º 1
0
 public function list_fields($db, $table)
 {
     $this->check();
     return @mysqli_list_fields($db, $table, $this->db);
 }
Exemplo n.º 2
0
 /**
  * Returns information about a table or a result set.
  *
  * WARNING: this method will probably not work because the mysqli_*()
  * functions it relies upon may not exist.
  *
  * @param object|string  $result  DB_result object from a query or a
  *                                string containing the name of a table
  * @param int            $mode    a valid tableInfo mode
  * @return array  an associative array with the information requested
  *                or an error object if something is wrong
  * @access public
  * @internal
  * @see DB_common::tableInfo()
  */
 function tableInfo($result, $mode = null)
 {
     if (isset($result->result)) {
         /*
          * Probably received a result object.
          * Extract the result resource identifier.
          */
         $id = $result->result;
         $got_string = false;
     } elseif (is_string($result)) {
         /*
          * Probably received a table name.
          * Create a result resource identifier.
          */
         $id = @mysqli_list_fields($this->dsn['database'], $result, $this->connection);
         $got_string = true;
     } else {
         /*
          * Probably received a result resource identifier.
          * Copy it.
          * Depricated.  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 = @mysqli_num_fields($id);
     // made this IF due to performance (one if is faster than $count if's)
     if (!$mode) {
         for ($i = 0; $i < $count; $i++) {
             $res[$i]['table'] = $case_func(@mysqli_field_table($id, $i));
             $res[$i]['name'] = $case_func(@mysqli_field_name($id, $i));
             $res[$i]['type'] = @mysqli_field_type($id, $i);
             $res[$i]['len'] = @mysqli_field_len($id, $i);
             $res[$i]['flags'] = @mysqli_field_flags($id, $i);
         }
     } else {
         // full
         $res['num_fields'] = $count;
         for ($i = 0; $i < $count; $i++) {
             $res[$i]['table'] = $case_func(@mysqli_field_table($id, $i));
             $res[$i]['name'] = $case_func(@mysqli_field_name($id, $i));
             $res[$i]['type'] = @mysqli_field_type($id, $i);
             $res[$i]['len'] = @mysqli_field_len($id, $i);
             $res[$i]['flags'] = @mysqli_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) {
         @mysqli_free_result($id);
     }
     return $res;
 }
Exemplo n.º 3
0
 /**
  * Returns information about a table or a result set.
  *
  * WARNING: this method will probably not work because the mysqli_*()
  * functions it relies upon may not exist.
  *
  * @param object|string  $result  DB_result object from a query or a
  *                                string containing the name of a table
  * @param int            $mode    a valid tableInfo mode
  * @return array  an associative array with the information requested
  *                or an error object if something is wrong
  * @access public
  * @internal
  * @see DB_common::tableInfo()
  */
 function tableInfo($result, $mode = null)
 {
     if (isset($result->result)) {
         /*
          * Probably received a result object.
          * Extract the result resource identifier.
          */
         $id = $result->result;
         $got_string = false;
     } elseif (is_string($result)) {
         /*
          * Probably received a table name.
          * Create a result resource identifier.
          */
         $id = @mysqli_list_fields($this->dsn['database'], $result, $this->connection);
         $got_string = true;
     } else {
         /*
          * Probably received a result resource identifier.
          * Copy it.
          * Depricated.  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 = @mysqli_num_fields($id);
     // made this IF due to performance (one if is faster than $count if's)
     if (!$mode) {
         for ($i = 0; $i < $count; $i++) {
             $tmp = @mysqli_fetch_field($id);
             $res[$i]['table'] = $case_func($tmp->table);
             $res[$i]['name'] = $case_func($tmp->name);
             $res[$i]['type'] = $tmp->type;
             $res[$i]['len'] = $tmp->max_length;
             $res[$i]['flags'] = '';
             if ($tmp->flags & MYSQLI_NOT_NULL_FLAG) {
                 $res[$i]['flags'] .= 'not_null ';
             }
             if ($tmp->flags & MYSQLI_PRI_KEY_FLAG) {
                 $res[$i]['flags'] .= 'primary_key ';
             }
             if ($tmp->flags & MYSQLI_UNIQUE_KEY_FLAG) {
                 $res[$i]['flags'] .= 'unique_key ';
             }
             if ($tmp->flags & MYSQLI_MULTIPLE_KEY_FLAG) {
                 $res[$i]['flags'] .= 'multiple_key ';
             }
             if ($tmp->flags & MYSQLI_BLOB_FLAG) {
                 $res[$i]['flags'] .= 'blob ';
             }
             if ($tmp->def) {
                 $res[$i]['flags'] .= 'default_' . rawurlencode($tmp->def);
             }
             $res[$i]['flags'] = trim($res[$i]['flags']);
         }
     } else {
         // full
         $res['num_fields'] = $count;
         for ($i = 0; $i < $count; $i++) {
             $tmp = @mysqli_fetch_field($id);
             $res[$i]['table'] = $case_func($tmp->table);
             $res[$i]['name'] = $case_func($tmp->name);
             $res[$i]['type'] = $tmp->type;
             $res[$i]['len'] = $tmp->max_length;
             $res[$i]['flags'] = '';
             if ($tmp->flags & MYSQLI_NOT_NULL_FLAG) {
                 $res[$i]['flags'] .= 'not_null ';
             }
             if ($tmp->flags & MYSQLI_PRI_KEY_FLAG) {
                 $res[$i]['flags'] .= 'primary_key ';
             }
             if ($tmp->flags & MYSQLI_UNIQUE_KEY_FLAG) {
                 $res[$i]['flags'] .= 'unique_key ';
             }
             if ($tmp->flags & MYSQLI_MULTIPLE_KEY_FLAG) {
                 $res[$i]['flags'] .= 'multiple_key ';
             }
             if ($tmp->flags & MYSQLI_BLOB_FLAG) {
                 $res[$i]['flags'] .= 'blob ';
             }
             if ($tmp->def) {
                 $res[$i]['flags'] .= 'default_' . rawurlencode($tmp->def);
             }
             $res[$i]['flags'] = trim($res[$i]['flags']);
             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) {
         @mysqli_free_result($id);
     }
     return $res;
 }
Exemplo n.º 4
0
 function list_fields($table_name)
 {
     return mysqli_list_fields($this->db, $this->link, $table_name);
 }