From 74cc95fe29543ed509f96e5e4348d27c4cf8a01e Mon Sep 17 00:00:00 2001 From: Marcel Tschopp Date: Thu, 8 Apr 2004 12:30:40 +0000 Subject: [PATCH] phpMyAdmin should now be fully compatible with the new mysqli extension. --- ChangeLog | 7 +++ libraries/dbi/mysql.dbi.lib.php | 8 +++ libraries/dbi/mysqli.dbi.lib.php | 89 ++++++++++++++++++++++++++++++ libraries/display_tbl.lib.php | 6 +- libraries/export/csv.php | 4 +- libraries/export/latex.php | 4 +- libraries/export/sql.php | 2 +- libraries/export/xml.php | 2 +- libraries/mysql_wrappers.lib.php | 95 +------------------------------- phpinfo.php | 2 +- tbl_relation.php | 2 +- 11 files changed, 116 insertions(+), 105 deletions(-) diff --git a/ChangeLog b/ChangeLog index f56068c8c..e952283d1 100755 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,13 @@ phpMyAdmin - Changelog $Id$ $Source$ +2004-04-08 Marcel Tschopp + * phpinfo.php, tbl_relation.php, libraries/display_tbl.lib.php + libraries/mysql_wrappers.lib.php, libraries/dbi/mysql.dbi.lib.php + libraries/dbi/mysqli.dbi.lib.php, libraries/export/*.php: + phpMyAdmin should now be fully compatible with the new mysqli + extension. All extension specific functions are wrapped now. + 2004-04-07 Marcel Tschopp * multi_submits.inc.php, lang/german: bug 930714, wrong spelling and query display. Thanks to Daniel Marschall (blackdrake) diff --git a/libraries/dbi/mysql.dbi.lib.php b/libraries/dbi/mysql.dbi.lib.php index 3ef54b7ec..e513c2752 100644 --- a/libraries/dbi/mysql.dbi.lib.php +++ b/libraries/dbi/mysql.dbi.lib.php @@ -259,4 +259,12 @@ function PMA_DBI_field_len($result, $i) { return mysql_field_len($result, $i); } +function PMA_DBI_field_name($result, $i) { + return mysql_field_name($result, $field_index); +} + +function PMA_DBI_field_flags($result, $i) { + return PMA_mysql_field_flags($result, $i); +} + ?> diff --git a/libraries/dbi/mysqli.dbi.lib.php b/libraries/dbi/mysqli.dbi.lib.php index 2cc63f200..7977f3cfe 100644 --- a/libraries/dbi/mysqli.dbi.lib.php +++ b/libraries/dbi/mysqli.dbi.lib.php @@ -357,4 +357,93 @@ function PMA_DBI_field_len($result, $i) { return $info->length; } +function PMA_DBI_field_name($result, $i) { + $info = mysqli_fetch_field_direct($result, $i); + return $info->name; +} + +function PMA_DBI_field_flags($result, $i) { + $f = mysqli_fetch_field_direct($result, $i); + $f = $f->flags; + $flags = ''; + while ($f > 0) { + if (floor($f / 65536)) { + $flags .= 'unique '; + $f -= 65536; + continue; + } + if (floor($f / 32768)) { + $flags .= 'num '; + $f -= 32768; + continue; + } + if (floor($f / 16384)) { + $flags .= 'part_key '; + $f -= 16384; + continue; + } + if (floor($f / 2048)) { + $flags .= 'set '; + $f -= 2048; + continue; + } + if (floor($f / 1024)) { + $flags .= 'timestamp '; + $f -= 1024; + continue; + }if (floor($f / 512)) { + $flags .= 'auto_increment '; + $f -= 512; + continue; + } + if (floor($f / 256)) { + $flags .= 'enum '; + $f -= 256; + continue; + } + if (floor($f / 128)) { + $flags .= 'binary '; + $f -= 128; + continue; + } + if (floor($f / 64)) { + $flags .= 'zerofill '; + $f -= 64; + continue; + } + if (floor($f / 32)) { + $flags .= 'unsigned '; + $f -= 32; + continue; + } + if (floor($f / 16)) { + $flags .= 'blob '; + $f -= 16; + continue; + } + if (floor($f / 8)) { + $flags .= 'multiple_key '; + $f -= 8; + continue; + } + if (floor($f / 4)) { + $flags .= 'unique_key '; + $f -= 4; + continue; + } + if (floor($f / 2)) { + $flags .= 'primary_key '; + $f -= 2; + continue; + } + if (floor($f / 1)) { + $flags .= 'not_null '; + $f -= 1; + continue; + } + } + return PMA_convert_display_charset(trim($flags)); +} + + ?> diff --git a/libraries/display_tbl.lib.php b/libraries/display_tbl.lib.php index 0a7507f56..c447dea23 100644 --- a/libraries/display_tbl.lib.php +++ b/libraries/display_tbl.lib.php @@ -1035,7 +1035,7 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) // "primary" key to use in links if ($is_display['edit_lnk'] == 'ur' /* || $is_display['edit_lnk'] == 'dr' */) { for ($i = 0; $i < $fields_cnt; ++$i) { - $field_flags = PMA_mysql_field_flags($dt_result, $i); // !UNWRAPPED FUNCTION! + $field_flags = PMA_DBI_field_flags($dt_result, $i); $meta = $fields_meta[$i]; // do not use an alias in a condition $column_for_condition = $meta->name; @@ -1351,7 +1351,7 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) // TEXT fields type, however TEXT fields must be displayed // even if $cfg['ShowBlob'] is false -> get the true type // of the fields. - $field_flags = PMA_mysql_field_flags($dt_result, $i); // !UNWRAPPED FUNCTION! + $field_flags = PMA_DBI_field_flags($dt_result, $i); if (stristr($field_flags, 'BINARY')) { $blobtext = '[BLOB'; if (isset($row[$pointer])) { @@ -1398,7 +1398,7 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) } // loic1: displays special characters from binaries - $field_flags = PMA_mysql_field_flags($dt_result, $i); // !UNWRAPPED FUNCTION! + $field_flags = PMA_DBI_field_flags($dt_result, $i); if (stristr($field_flags, 'BINARY')) { $row[$pointer] = str_replace("\x00", '\0', $row[$pointer]); $row[$pointer] = str_replace("\x08", '\b', $row[$pointer]); diff --git a/libraries/export/csv.php b/libraries/export/csv.php index a8c5c351f..25f6b02ab 100644 --- a/libraries/export/csv.php +++ b/libraries/export/csv.php @@ -121,10 +121,10 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { $schema_insert = ''; for ($i = 0; $i < $fields_cnt; $i++) { if ($enclosed == '') { - $schema_insert .= stripslashes(mysql_field_name($result, $i)); //! UNWRAPPED FUNCTION! + $schema_insert .= stripslashes(PMA_DBI_field_name($result, $i)); } else { $schema_insert .= $enclosed - . str_replace($enclosed, $escaped . $enclosed, stripslashes(mysql_field_name($result, $i))) //! UNWRAPPED FUNCTION! + . str_replace($enclosed, $escaped . $enclosed, stripslashes(PMA_DBI_field_name($result, $i))) . $enclosed; } $schema_insert .= $separator; diff --git a/libraries/export/latex.php b/libraries/export/latex.php index ba67cbf5c..6f5f7eb7b 100644 --- a/libraries/export/latex.php +++ b/libraries/export/latex.php @@ -118,11 +118,11 @@ function PMA_exportDBCreate($db) { * @access public */ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { - $result = PMA_mysql_query($sql_query, NULL, PMA_DBI_QUERY_UNBUFFERED); + $result = PMA_DBI_try_query($sql_query, NULL, PMA_DBI_QUERY_UNBUFFERED); $columns_cnt = PMA_DBI_num_fields($result); for ($i = 0; $i < $columns_cnt; $i++) { - $columns[$i] = mysql_field_name($result, $i); + $columns[$i] = PMA_DBI_field_name($result, $i); } unset($i); diff --git a/libraries/export/sql.php b/libraries/export/sql.php index 6108a5737..0ecb494e9 100644 --- a/libraries/export/sql.php +++ b/libraries/export/sql.php @@ -434,7 +434,7 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) if (isset($analyzed_sql[0]['select_expr'][$j]['column'])) { $field_set[$j] = PMA_backquote($analyzed_sql[0]['select_expr'][$j]['column'], $use_backquotes); } else { - $field_set[$j] = PMA_backquote(PMA_mysql_field_name($result, $j), $use_backquotes); //! UNWRAPPED FUNCTION! + $field_set[$j] = PMA_backquote(PMA_DBI_field_name($result, $j), $use_backquotes); } $type = $field_types[$field_set[$j]]; diff --git a/libraries/export/xml.php b/libraries/export/xml.php index 625fb070e..c6fe1855d 100644 --- a/libraries/export/xml.php +++ b/libraries/export/xml.php @@ -117,7 +117,7 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { $columns_cnt = PMA_DBI_num_fields($result); for ($i = 0; $i < $columns_cnt; $i++) { - $columns[$i] = stripslashes(mysql_field_name($result, $i)); //! UNWRAPPED FUNCTION! + $columns[$i] = stripslashes(PMA_DBI_field_name($result, $i)); } unset($i); diff --git a/libraries/mysql_wrappers.lib.php b/libraries/mysql_wrappers.lib.php index 0ee232d43..216eadfe8 100644 --- a/libraries/mysql_wrappers.lib.php +++ b/libraries/mysql_wrappers.lib.php @@ -46,100 +46,7 @@ function PMA_mysql_fetch_row($result) { } function PMA_mysql_field_flags($result, $field_offset) { - /* ne0x/swix: added a switch for the mysqli extention because mysqli does not know - the function mysqli_field_flags */ - - global $cfg; - - switch ($cfg['Server']['extension']) { - case "mysqli": - $f = mysqli_fetch_field_direct($result, $field_offset); - $f = $f->flags; - $flags = ''; - while ($f > 0) { - if (floor($f / 65536)) { - $flags .= 'unique '; - $f -= 65536; - continue; - } - if (floor($f / 32768)) { - $flags .= 'num '; - $f -= 32768; - continue; - } - if (floor($f / 16384)) { - $flags .= 'part_key '; - $f -= 16384; - continue; - } - if (floor($f / 2048)) { - $flags .= 'set '; - $f -= 2048; - continue; - } - if (floor($f / 1024)) { - $flags .= 'timestamp '; - $f -= 1024; - continue; - }if (floor($f / 512)) { - $flags .= 'auto_increment '; - $f -= 512; - continue; - } - if (floor($f / 256)) { - $flags .= 'enum '; - $f -= 256; - continue; - } - if (floor($f / 128)) { - $flags .= 'binary '; - $f -= 128; - continue; - } - if (floor($f / 64)) { - $flags .= 'zerofill '; - $f -= 64; - continue; - } - if (floor($f / 32)) { - $flags .= 'unsigned '; - $f -= 32; - continue; - } - if (floor($f / 16)) { - $flags .= 'blob '; - $f -= 16; - continue; - } - if (floor($f / 8)) { - $flags .= 'multiple_key '; - $f -= 8; - continue; - } - if (floor($f / 4)) { - $flags .= 'unique_key '; - $f -= 4; - continue; - } - if (floor($f / 2)) { - $flags .= 'primary_key '; - $f -= 2; - continue; - } - if (floor($f / 1)) { - $flags .= 'not_null '; - $f -= 1; - continue; - } - } - return PMA_convert_display_charset(trim($flags)); - - case "mysql": - default: - return PMA_convert_display_charset(mysql_field_flags($result, $field_offset)); - - - } + return PMA_convert_display_charset(mysql_field_flags($result, $field_offset)); } function PMA_mysql_field_name($result, $field_index) { diff --git a/phpinfo.php b/phpinfo.php index 30c7f9fd6..ee485a85f 100644 --- a/phpinfo.php +++ b/phpinfo.php @@ -13,7 +13,7 @@ require_once('./libraries/common.lib.php'); /** * Displays PHP information */ -$is_superuser = @PMA_mysql_query('USE mysql', $userlink); +$is_superuser = @PMA_DBI_try_query('USE mysql', $userlink); if ($is_superuser || $cfg['ShowPhpInfo']) { phpinfo(); } diff --git a/tbl_relation.php b/tbl_relation.php index d39e6a666..7c832be2d 100644 --- a/tbl_relation.php +++ b/tbl_relation.php @@ -337,7 +337,7 @@ if ($cfgRelation['relwork']) { // Now find out the columns of our $table -$col_rs = PMA_mysql_query('SHOW COLUMNS FROM ' . PMA_backquote($table) . ';'); +$col_rs = PMA_DBI_try_query('SHOW COLUMNS FROM ' . PMA_backquote($table) . ';'); if ($col_rs && PMA_DBI_num_rows($col_rs) > 0) { while ($row = PMA_DBI_fetch_assoc($col_rs)) {