First batch of PHP4/MySQL compatibility/performance changes.

Everything should be non-intrusive for installations meeting our new 4.1.0/3.23.32 specs.

I will commit my files every now and then for easier code review and to let you see which constructs I replace. Jump in if there are any objections. The basic thing I'm doing is documented in the changelog.

I'll continue with files in the libraries/ subdirectory and will move to the root-level files in last instance.
This commit is contained in:
Garvin Hicking
2003-11-20 10:34:35 +00:00
parent f7c93f5bb1
commit d3f84bca94
7 changed files with 132 additions and 368 deletions

View File

@@ -5,6 +5,20 @@ phpMyAdmin - Changelog
$Id$
$Source$
2003-11-20 Garvin Hicking <me@supergarv.de>
* libraries/auth/*, libraries/dbg/*, libraries/export/*
(work in progress)
Lots of PHP < 4.1.0 / MySQL < 3.23.32 compatibility/performance changes:
- Replaced "while (list() = each())" calls by foreach loops.
- Removed PHP3-compatibility code
- Removed calls to $HTTP_*_VARS (using $_* now).
- Replaced some TAB-characters with whitespace
- Removed PHP4 < 4.1.0 compatibility code
- Replaced "for ($i=0; $i <= count(); $i++)" loops to
"$cnt = count(); for ($i=0; $i <= $cnt; $i++)" structures for better
performance
2003-11-19 Marc Delisle <lem9@users.sourceforge.net>
* libraries/display_tbl.lib.php: first group of headers was offset by
one column to the left

View File

@@ -16,17 +16,6 @@ if (!defined('PMA_COOKIE_AUTH_INCLUDED')) {
if (!isset($coming_from_common)) {
exit();
}
// emulate array_values() for PHP 3
// if (PMA_PHP_INT_VERSION < 40000) {
if (!@function_exists('array_values')) {
function array_values ($arr) {
$t = array();
while (list($k, $v) = each ($arr)) {
$t[] = $v;
}
return $t;
} // end function
} // end if
include('./libraries/blowfish.php');
@@ -154,7 +143,6 @@ function PMA_blowfish_decrypt($data, $secret) {
global $cfg, $available_languages;
global $lang, $server, $convcharset;
global $conn_error;
global $HTTP_COOKIE_VARS;
// Tries to get the username from cookie whatever are the values of the
// 'register_globals' and the 'variables_order' directives if last login
@@ -167,9 +155,7 @@ function PMA_blowfish_decrypt($data, $secret) {
else if (!empty($_COOKIE) && isset($_COOKIE['pma_cookie_username'])) {
$default_user = $_COOKIE['pma_cookie_username'];
}
else if (!empty($HTTP_COOKIE_VARS) && isset($HTTP_COOKIE_VARS['pma_cookie_username'])) {
$default_user = $HTTP_COOKIE_VARS['pma_cookie_username'];
}
if (isset($default_user) && get_magic_quotes_gpc()) {
$default_user = stripslashes($default_user);
}
@@ -181,9 +167,6 @@ function PMA_blowfish_decrypt($data, $secret) {
else if (!empty($_COOKIE) && isset($_COOKIE['pma_cookie_servername'])) {
$default_server = $_COOKIE['pma_cookie_servername'];
}
else if (!empty($HTTP_COOKIE_VARS) && isset($HTTP_COOKIE_VARS['pma_cookie_servername'])) {
$default_server = $HTTP_COOKIE_VARS['pma_cookie_servername'];
}
if (isset($default_server) && get_magic_quotes_gpc()) {
$default_server = stripslashes($default_server);
}
@@ -242,8 +225,7 @@ input.textfield {font-family: <?php echo $right_font_family; ?>; font-size: <?ph
echo "\n";
uasort($available_languages, 'PMA_cookie_cmp');
reset($available_languages);
while (list($id, $tmplang) = each($available_languages)) {
foreach($available_languages AS $id => $tmplang) {
$lang_name = ucfirst(substr(strstr($tmplang[0], '|'), 1));
if ($lang == $id) {
$selected = ' selected="selected"';
@@ -317,8 +299,7 @@ input.textfield {font-family: <?php echo $right_font_family; ?>; font-size: <?ph
<?php
echo "\n";
// Displays the MySQL servers choice
reset($cfg['Servers']);
while (list($key, $val) = each($cfg['Servers'])) {
foreach($cfg['Servers'] AS $key => $val) {
if (!empty($val['host']) || $val['auth_type'] == 'arbitrary') {
echo ' <option value="' . $key . '"';
if (!empty($server) && ($server == $key)) {
@@ -362,9 +343,7 @@ input.textfield {font-family: <?php echo $right_font_family; ?>; font-size: <?ph
?>
<?php
if (!empty($conn_error)) {
echo '<tr><td colspan="2" align="center"><p class="warning">'.
$conn_error.
'</p></td></tr>'."\n";
echo '<tr><td colspan="2" align="center"><p class="warning">'. $conn_error . '</p></td></tr>' . "\n";
}
?>
<tr>
@@ -426,7 +405,6 @@ if (uname.value == '') {
function PMA_auth_check()
{
global $PHP_AUTH_USER, $PHP_AUTH_PW, $pma_auth_server;
global $HTTP_COOKIE_VARS;
global $pma_servername, $pma_username, $pma_password, $old_usr;
global $from_cookie;
@@ -464,10 +442,6 @@ if (uname.value == '') {
$pma_auth_server = $_COOKIE['pma_cookie_servername'];
$from_cookie = TRUE;
}
else if (!empty($HTTP_COOKIE_VARS) && isset($HTTP_COOKIE_VARS['pma_cookie_servername'])) {
$pma_auth_server = $HTTP_COOKIE_VARS['pma_cookie_servername'];
$from_cookie = TRUE;
}
}
// username
if (!empty($pma_cookie_username)) {
@@ -478,10 +452,6 @@ if (uname.value == '') {
$PHP_AUTH_USER = $_COOKIE['pma_cookie_username'];
$from_cookie = TRUE;
}
else if (!empty($HTTP_COOKIE_VARS) && isset($HTTP_COOKIE_VARS['pma_cookie_username'])) {
$PHP_AUTH_USER = $HTTP_COOKIE_VARS['pma_cookie_username'];
$from_cookie = TRUE;
}
// password
if (!empty($pma_cookie_password)) {
$PHP_AUTH_PW = $pma_cookie_password;
@@ -489,9 +459,6 @@ if (uname.value == '') {
else if (!empty($_COOKIE) && isset($_COOKIE['pma_cookie_password'])) {
$PHP_AUTH_PW = $_COOKIE['pma_cookie_password'];
}
else if (!empty($HTTP_COOKIE_VARS) && isset($HTTP_COOKIE_VARS['pma_cookie_password'])) {
$PHP_AUTH_PW = $HTTP_COOKIE_VARS['pma_cookie_password'];
}
else {
$from_cookie = FALSE;
}
@@ -601,9 +568,6 @@ if (uname.value == '') {
if (isset($_SERVER) && !empty($_SERVER['SERVER_SOFTWARE'])) {
$GLOBALS['SERVER_SOFTWARE'] = $_SERVER['SERVER_SOFTWARE'];
}
else if (isset($GLOBALS['HTTP_SERVER_VARS']) && !empty($GLOBALS['HTTP_SERVER_VARS']['SERVER_SOFTWARE'])) {
$GLOBALS['SERVER_SOFTWARE'] = $GLOBALS['HTTP_SERVER_VARS']['SERVER_SOFTWARE'];
}
} // end if
if (!empty($GLOBALS['SERVER_SOFTWARE']) && $GLOBALS['SERVER_SOFTWARE'] == 'Microsoft-IIS/5.0') {
header('Refresh: 0; url=' . $cfg['PmaAbsoluteUri'] . 'index.php?' . PMA_generate_common_url('', '', '&'));

View File

@@ -88,7 +88,6 @@ h1 {font-family: <?php echo $right_font_family; ?>; font-size: <?php echo
function PMA_auth_check()
{
global $PHP_AUTH_USER, $PHP_AUTH_PW;
global $HTTP_SERVER_VARS, $HTTP_ENV_VARS;
global $REMOTE_USER, $AUTH_USER, $REMOTE_PASSWORD, $AUTH_PASSWORD;
global $HTTP_AUTHORIZATION;
global $old_usr;
@@ -100,18 +99,12 @@ h1 {font-family: <?php echo $right_font_family; ?>; font-size: <?php echo
if (!empty($_SERVER) && isset($_SERVER['PHP_AUTH_USER'])) {
$PHP_AUTH_USER = $_SERVER['PHP_AUTH_USER'];
}
else if (!empty($HTTP_SERVER_VARS) && isset($HTTP_SERVER_VARS['PHP_AUTH_USER'])) {
$PHP_AUTH_USER = $HTTP_SERVER_VARS['PHP_AUTH_USER'];
}
else if (isset($REMOTE_USER)) {
$PHP_AUTH_USER = $REMOTE_USER;
}
else if (!empty($_ENV) && isset($_ENV['REMOTE_USER'])) {
$PHP_AUTH_USER = $_ENV['REMOTE_USER'];
}
else if (!empty($HTTP_ENV_VARS) && isset($HTTP_ENV_VARS['REMOTE_USER'])) {
$PHP_AUTH_USER = $HTTP_ENV_VARS['REMOTE_USER'];
}
else if (@getenv('REMOTE_USER')) {
$PHP_AUTH_USER = getenv('REMOTE_USER');
}
@@ -122,9 +115,6 @@ h1 {font-family: <?php echo $right_font_family; ?>; font-size: <?php echo
else if (!empty($_ENV) && isset($_ENV['AUTH_USER'])) {
$PHP_AUTH_USER = $_ENV['AUTH_USER'];
}
else if (!empty($HTTP_ENV_VARS) && isset($HTTP_ENV_VARS['AUTH_USER'])) {
$PHP_AUTH_USER = $HTTP_ENV_VARS['AUTH_USER'];
}
else if (@getenv('AUTH_USER')) {
$PHP_AUTH_USER = getenv('AUTH_USER');
}
@@ -136,18 +126,12 @@ h1 {font-family: <?php echo $right_font_family; ?>; font-size: <?php echo
if (!empty($_SERVER) && isset($_SERVER['PHP_AUTH_PW'])) {
$PHP_AUTH_PW = $_SERVER['PHP_AUTH_PW'];
}
else if (!empty($HTTP_SERVER_VARS) && isset($HTTP_SERVER_VARS['PHP_AUTH_PW'])) {
$PHP_AUTH_PW = $HTTP_SERVER_VARS['PHP_AUTH_PW'];
}
else if (isset($REMOTE_PASSWORD)) {
$PHP_AUTH_PW = $REMOTE_PASSWORD;
}
else if (!empty($_ENV) && isset($_ENV['REMOTE_PASSWORD'])) {
$PHP_AUTH_PW = $_ENV['REMOTE_PASSWORD'];
}
else if (!empty($HTTP_ENV_VARS) && isset($HTTP_ENV_VARS['REMOTE_PASSWORD'])) {
$PHP_AUTH_PW = $HTTP_ENV_VARS['REMOTE_PASSWORD'];
}
else if (@getenv('REMOTE_PASSWORD')) {
$PHP_AUTH_PW = getenv('REMOTE_PASSWORD');
}
@@ -158,9 +142,6 @@ h1 {font-family: <?php echo $right_font_family; ?>; font-size: <?php echo
else if (!empty($_ENV) && isset($_ENV['AUTH_PASSWORD'])) {
$PHP_AUTH_PW = $_ENV['AUTH_PASSWORD'];
}
else if (!empty($HTTP_ENV_VARS) && isset($HTTP_ENV_VARS['AUTH_PASSWORD'])) {
$PHP_AUTH_PW = $HTTP_ENV_VARS['AUTH_PASSWORD'];
}
else if (@getenv('AUTH_PASSWORD')) {
$PHP_AUTH_PW = getenv('AUTH_PASSWORD');
}
@@ -177,11 +158,6 @@ h1 {font-family: <?php echo $right_font_family; ?>; font-size: <?php echo
&& ereg('^Basic ', $_ENV['HTTP_AUTHORIZATION'])) {
list($PHP_AUTH_USER, $PHP_AUTH_PW) = explode(':', base64_decode(substr($_ENV['HTTP_AUTHORIZATION'], 6)));
}
else if (!empty($HTTP_ENV_VARS)
&& isset($HTTP_ENV_VARS['HTTP_AUTHORIZATION'])
&& ereg('^Basic ', $HTTP_ENV_VARS['HTTP_AUTHORIZATION'])) {
list($PHP_AUTH_USER, $PHP_AUTH_PW) = explode(':', base64_decode(substr($HTTP_ENV_VARS['HTTP_AUTHORIZATION'], 6)));
}
else if (@getenv('HTTP_AUTHORIZATION')
&& ereg('^Basic ', getenv('HTTP_AUTHORIZATION'))) {
list($PHP_AUTH_USER, $PHP_AUTH_PW) = explode(':', base64_decode(substr(getenv('HTTP_AUTHORIZATION'), 6)));

View File

@@ -37,8 +37,7 @@ if (!defined('PMA_DBG_PROFILING_INCLUDED')) {
'<td>' . $GLOBALS['strDBGContext'] . '</td>' . "\n" .
'</tr></thead>' . "\n" .
'<tbody style="vertical-align: top">' . "\n";
@reset($dbg_prof_results['line_no']);
while(list($idx, $line_no) = each($dbg_prof_results['line_no'])) {
foreach($dbg_prof_results['line_no'] AS $idx => $line_no) {
$mod_no = $dbg_prof_results['mod_no'][$idx];
dbg_get_module_name($mod_no, &$mod_name);

View File

@@ -9,7 +9,6 @@ if (!defined('PMA_DBG_SETUP_INCLUDED')) {
/**
* Loads the DBG extension if needed
*/
if (PMA_PHP_INT_VERSION >= 40000) {
if (!@extension_loaded('dbg')) {
PMA_dl('dbg');
}
@@ -21,6 +20,5 @@ if (!defined('PMA_DBG_SETUP_INCLUDED')) {
$GLOBALS['DBG'] = true;
}
}
}
?>

View File

@@ -17,7 +17,8 @@
*/
function PMA_texEscape($string) {
$escape = array('$', '%', '{', '}', '&', '#', '_', '^');
for($k=0;$k<count($escape);$k++) {
$cnt_escape = count($escape);
for($k=0; $k < $cnt_escape; $k++) {
$string = str_replace($escape[$k], '\\' . $escape[$k], $string);
}
return $string;

View File

@@ -144,7 +144,6 @@ function PMA_getTableDef($db, $table, $crlf, $error_url, $show_dates = false)
$new_crlf = $crlf;
if (PMA_MYSQL_INT_VERSION >= 32321) {
$result = PMA_mysql_query('SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \'' . PMA_sqlAddslashes($table) . '\'');
if ($result != FALSE) {
if (mysql_num_rows($result) > 0) {
@@ -170,7 +169,6 @@ function PMA_getTableDef($db, $table, $crlf, $error_url, $show_dates = false)
mysql_free_result($result);
}
}
}
$schema_create .= $new_crlf;
@@ -179,8 +177,6 @@ function PMA_getTableDef($db, $table, $crlf, $error_url, $show_dates = false)
}
// Steve Alberty's patch for complete table dump,
// modified by Lem9 to allow older MySQL versions to continue to work
if (PMA_MYSQL_INT_VERSION >= 32321) {
// Whether to quote table and fields names or not
if ($use_backquotes) {
PMA_mysql_query('SET SQL_QUOTE_SHOW_CREATE = 1');
@@ -233,73 +229,6 @@ function PMA_getTableDef($db, $table, $crlf, $error_url, $show_dates = false)
mysql_free_result($result);
return $schema_create;
} // end if MySQL >= 3.23.21
// For MySQL < 3.23.20
$schema_create .= 'CREATE TABLE ' . PMA_backquote($table, $use_backquotes) . ' (' . $crlf;
$local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db);
$result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $error_url);
while ($row = PMA_mysql_fetch_array($result)) {
$schema_create .= ' ' . PMA_backquote($row['Field'], $use_backquotes) . ' ' . $row['Type'];
if (isset($row['Default']) && $row['Default'] != '') {
$schema_create .= ' DEFAULT \'' . PMA_sqlAddslashes($row['Default']) . '\'';
}
if ($row['Null'] != 'YES') {
$schema_create .= ' NOT NULL';
}
if ($row['Extra'] != '') {
$schema_create .= ' ' . $row['Extra'];
}
$schema_create .= ',' . $crlf;
} // end while
mysql_free_result($result);
$schema_create = ereg_replace(',' . $crlf . '$', '', $schema_create);
$local_query = 'SHOW KEYS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db);
$result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $error_url);
while ($row = PMA_mysql_fetch_array($result))
{
$kname = $row['Key_name'];
$comment = (isset($row['Comment'])) ? $row['Comment'] : '';
$sub_part = (isset($row['Sub_part'])) ? $row['Sub_part'] : '';
if ($kname != 'PRIMARY' && $row['Non_unique'] == 0) {
$kname = 'UNIQUE|' . $kname;
}
if ($comment == 'FULLTEXT') {
$kname = 'FULLTEXT|' . $kname;
}
if (!isset($index[$kname])) {
$index[$kname] = array();
}
if ($sub_part > 1) {
$index[$kname][] = PMA_backquote($row['Column_name'], $use_backquotes) . '(' . $sub_part . ')';
} else {
$index[$kname][] = PMA_backquote($row['Column_name'], $use_backquotes);
}
} // end while
mysql_free_result($result);
while (list($x, $columns) = @each($index)) {
$schema_create .= ',' . $crlf;
if ($x == 'PRIMARY') {
$schema_create .= ' PRIMARY KEY (';
} else if (substr($x, 0, 6) == 'UNIQUE') {
$schema_create .= ' UNIQUE ' . substr($x, 7) . ' (';
} else if (substr($x, 0, 8) == 'FULLTEXT') {
$schema_create .= ' FULLTEXT ' . substr($x, 9) . ' (';
} else {
$schema_create .= ' KEY ' . $x . ' (';
}
$schema_create .= implode($columns, ', ') . ')';
} // end while
$schema_create .= $crlf . ')';
return $schema_create;
} // end of the 'PMA_getTableDef()' function
@@ -578,118 +507,6 @@ function PMA_getTableContentFast($db, $table, $crlf, $error_url, $sql_query)
} // end of the 'PMA_getTableContentFast()' function
/**
* php < 4.0.5 only: get the content of $table as a series of INSERT
* statements.
*
* @param string the current database name
* @param string the current table name
* @param string the end of line sequence
* @param string the url to go back in case of error
* @param string the sql query
*
* @return bool Whether it suceeded
*
* @global boolean whether to use backquotes to allow the use of special
* characters in database, table and fields names or not
* @global integer the number of records
* @global integer the current record position
*
* @access private
*
* @see PMA_getTableContent()
*/
function PMA_getTableContentOld($db, $table, $crlf, $error_url, $sql_query)
{
global $use_backquotes;
global $rows_cnt;
global $current_row;
$eol_dlm = (isset($GLOBALS['extended_ins']) && ($GLOBALS['current_row'] < $GLOBALS['rows_cnt']))
? ','
: ';';
$buffer = '';
$result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', $sql_query, '', $error_url);
$current_row = 0;
$fields_cnt = mysql_num_fields($result);
$rows_cnt = mysql_num_rows($result);
while ($row = PMA_mysql_fetch_row($result)) {
$current_row++;
$table_list = '(';
for ($j = 0; $j < $fields_cnt; $j++) {
$table_list .= PMA_backquote(PMA_mysql_field_name($result, $j), $use_backquotes) . ', ';
}
$table_list = substr($table_list, 0, -2);
$table_list .= ')';
if (isset($GLOBALS['extended_ins']) && $current_row > 1) {
$schema_insert = '(';
} else {
if (isset($GLOBALS['showcolumns'])) {
$schema_insert = 'INSERT INTO ' . PMA_backquote($table, $use_backquotes)
. ' ' . $table_list . ' VALUES (';
} else {
$schema_insert = 'INSERT INTO ' . PMA_backquote($table, $use_backquotes)
. ' VALUES (';
}
$is_first_row = FALSE;
}
// get the real types of the table's fields (in an array)
// the key of the array is the backquoted field name
$field_types = PMA_fieldTypes($db,$table,$use_backquotes);
for ($j = 0; $j < $fields_cnt; $j++) {
if (!isset($row[$j])) {
$schema_insert .= ' NULL, ';
} else if ($row[$j] == '0' || $row[$j] != '') {
$type = $field_types[PMA_backquote(PMA_mysql_field_name($result, $j), $use_backquotes)];
// a number
if ($type == 'tinyint' || $type == 'smallint' || $type == 'mediumint' || $type == 'int' ||
$type == 'bigint' || (PMA_MYSQL_INT_VERSION < 40100 && $type == 'timestamp')) {
$schema_insert .= $row[$j] . ', ';
// blob
} else if (($type == 'blob' || $type == 'mediumblob' || $type == 'longblob' || $type == 'tinyblob') && !empty($row[$j])) {
$schema_insert .= '0x' . bin2hex($row[$j]) . ', ';
// a string
} else {
$dummy = '';
$srcstr = $row[$j];
for ($xx = 0; $xx < strlen($srcstr); $xx++) {
$yy = strlen($dummy);
if ($srcstr[$xx] == '\\') $dummy .= '\\\\';
if ($srcstr[$xx] == '\'') $dummy .= '\\\'';
// if ($srcstr[$xx] == '"') $dummy .= '\\"';
if ($srcstr[$xx] == "\x00") $dummy .= '\0';
if ($srcstr[$xx] == "\x0a") $dummy .= '\n';
if ($srcstr[$xx] == "\x0d") $dummy .= '\r';
// if ($srcstr[$xx] == "\x08") $dummy .= '\b';
// if ($srcstr[$xx] == "\t") $dummy .= '\t';
if ($srcstr[$xx] == "\x1a") $dummy .= '\Z';
if (strlen($dummy) == $yy) $dummy .= $srcstr[$xx];
}
$schema_insert .= "'" . $dummy . "', ";
}
} else {
$schema_insert .= "'', ";
} // end if
} // end for
$schema_insert = trim(ereg_replace(', $', '', $schema_insert));
$schema_insert .= ')';
if (!PMA_exportOutputHandler($schema_insert . $eol_dlm . $crlf)) return FALSE;
} // end while
mysql_free_result($result);
return TRUE;
} // end of the 'PMA_getTableContentOld()' function
/**
* Dispatches between the versions of 'getTableContent' to use depending
* on the php version
@@ -721,11 +538,6 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
. '#' . $crlf .$crlf;
if (!PMA_exportOutputHandler($head)) return FALSE;
// Call the working function depending on the php version
if (PMA_PHP_INT_VERSION >= 40005) {
return PMA_getTableContentFast($db, $table, $crlf, $error_url, $sql_query);
} else {
return PMA_getTableContentOld($db, $table, $crlf, $error_url, $sql_query);
}
} // end of the 'PMA_exportData()' function
?>