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');
@@ -40,7 +29,7 @@ if (!defined('PMA_COOKIE_AUTH_INCLUDED')) {
/**
* String padding
*
* @param string input string
* @param string input string
* @param integer length of the result
* @param string the filling string
* @param integer padding mode
@@ -80,18 +69,18 @@ if (!defined('PMA_COOKIE_AUTH_INCLUDED')) {
*
* @author lem9
*/
function PMA_blowfish_encrypt($data, $secret) {
$pma_cipher = new Horde_Cipher_blowfish;
$encrypt = '';
for ($i=0; $i<strlen($data); $i+=8) {
$block = substr($data, $i, 8);
if (strlen($block) < 8) {
$block = full_str_pad($block,8,"\0", 1);
function PMA_blowfish_encrypt($data, $secret) {
$pma_cipher = new Horde_Cipher_blowfish;
$encrypt = '';
for ($i=0; $i<strlen($data); $i+=8) {
$block = substr($data, $i, 8);
if (strlen($block) < 8) {
$block = full_str_pad($block,8,"\0", 1);
}
$encrypt .= $pma_cipher->encryptBlock($block, $secret);
}
$encrypt .= $pma_cipher->encryptBlock($block, $secret);
}
return $encrypt;
}
return $encrypt;
}
/**
* Decryption using blowfish algorithm
@@ -105,14 +94,14 @@ function PMA_blowfish_encrypt($data, $secret) {
*
* @author lem9
*/
function PMA_blowfish_decrypt($data, $secret) {
$pma_cipher = new Horde_Cipher_blowfish;
$decrypt = '';
for ($i=0; $i<strlen($data); $i+=8) {
$decrypt .= $pma_cipher->decryptBlock(substr($data, $i, 8), $secret);
}
return trim($decrypt);
}
function PMA_blowfish_decrypt($data, $secret) {
$pma_cipher = new Horde_Cipher_blowfish;
$decrypt = '';
for ($i=0; $i<strlen($data); $i+=8) {
$decrypt .= $pma_cipher->decryptBlock(substr($data, $i, 8), $secret);
}
return trim($decrypt);
}
/**
* Sorts available languages by their true names
@@ -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,13 +155,11 @@ 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);
}
// server name
if (!empty($GLOBALS['pma_cookie_servername'])) {
$default_server = $GLOBALS['pma_cookie_servername'];
@@ -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;
}
@@ -553,9 +520,9 @@ if (uname.value == '') {
}
} // end for
} // end if
$pma_server_changed = FALSE;
if ($GLOBALS['cfg']['AllowArbitraryServer']
if ($GLOBALS['cfg']['AllowArbitraryServer']
&& isset($pma_auth_server) && !empty($pma_auth_server)
&& ($cfg['Server']['host'] != $pma_auth_server)
) {
@@ -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('', '', '&'));
@@ -627,7 +591,7 @@ if (uname.value == '') {
*/
function PMA_auth_fails()
{
global $conn_error;
global $conn_error;
// Deletes password cookie and displays the login form
setcookie('pma_cookie_password', base64_encode(''), 0, $GLOBALS['cookie_path'], '' , $GLOBALS['is_https']);

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

@@ -5,8 +5,8 @@
if (!defined('PMA_DBG_PROFILING_INCLUDED')) {
define('PMA_DBG_PROFILING_INCLUDED', 1);
if (isset($GLOBALS['DBG']) && $GLOBALS['DBG']
&& isset($GLOBALS['cfg']['DBG']['profile']['enable'])
if (isset($GLOBALS['DBG']) && $GLOBALS['DBG']
&& isset($GLOBALS['cfg']['DBG']['profile']['enable'])
&& $GLOBALS['cfg']['DBG']['profile']['enable']) {
/**
@@ -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);
@@ -59,7 +58,7 @@ if (!defined('PMA_DBG_PROFILING_INCLUDED')) {
dbg_get_source_context($mod_no, $line_no, &$ctx_id);
//use a default context name if needed
if (dbg_get_context_name($ctx_id, &$ctx_name)
if (dbg_get_context_name($ctx_id, &$ctx_name)
&& strcmp($ctx_name,'') == 0) {
$ctx_name = "::main";
}

View File

@@ -9,17 +9,15 @@ 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');
}
if (!@extension_loaded('dbg')) {
echo sprintf($strCantLoad, 'DBG') . '<br />' . "\n"
. '<a href="./Documentation.html#faqdbg" target="documentation">' . $GLOBALS['strDocu'] . '</a>' . "\n";
exit();
}
$GLOBALS['DBG'] = true;
if (!@extension_loaded('dbg')) {
PMA_dl('dbg');
}
if (!@extension_loaded('dbg')) {
echo sprintf($strCantLoad, 'DBG') . '<br />' . "\n"
. '<a href="./Documentation.html#faqdbg" target="documentation">' . $GLOBALS['strDocu'] . '</a>' . "\n";
exit();
}
$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;
@@ -44,7 +45,7 @@ function PMA_exportComment($text) {
function PMA_exportHeader() {
global $crlf;
global $cfg;
$head = '% phpMyAdmin LaTeX Dump' . $crlf
. '% version ' . PMA_VERSION . $crlf
. '% http://www.phpmyadmin.net' . $crlf
@@ -139,7 +140,7 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) {
. '} \\label{' . str_replace('__TABLE__', $table, $GLOBALS['latex_data_label']) . '} \\\\';
}
if (!PMA_exportOutputHandler($buffer)) return FALSE;
// show column names
if (isset($GLOBALS['latex_showcolumns'])) {
$buffer = '\\hline ';

View File

@@ -144,31 +144,29 @@ 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) {
$tmpres = PMA_mysql_fetch_array($result);
if (isset($GLOBALS['auto_increment']) && !empty($tmpres['Auto_increment'])) {
$auto_increment .= ' AUTO_INCREMENT=' . $tmpres['Auto_increment'] . ' ';
}
if ($show_dates && isset($tmpres['Create_time']) && !empty($tmpres['Create_time'])) {
$schema_create .= '# ' . $GLOBALS['strStatCreateTime'] . ': ' . PMA_localisedDate(strtotime($tmpres['Create_time'])) . $crlf;
$new_crlf = '#' . $crlf . $crlf;
}
if ($show_dates && isset($tmpres['Update_time']) && !empty($tmpres['Update_time'])) {
$schema_create .= '# ' . $GLOBALS['strStatUpdateTime'] . ': ' . PMA_localisedDate(strtotime($tmpres['Update_time'])) . $crlf;
$new_crlf = '#' . $crlf . $crlf;
}
if ($show_dates && isset($tmpres['Check_time']) && !empty($tmpres['Check_time'])) {
$schema_create .= '# ' . $GLOBALS['strStatCheckTime'] . ': ' . PMA_localisedDate(strtotime($tmpres['Check_time'])) . $crlf;
$new_crlf = '#' . $crlf . $crlf;
}
mysql_free_result($result);
$result = PMA_mysql_query('SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \'' . PMA_sqlAddslashes($table) . '\'');
if ($result != FALSE) {
if (mysql_num_rows($result) > 0) {
$tmpres = PMA_mysql_fetch_array($result);
if (isset($GLOBALS['auto_increment']) && !empty($tmpres['Auto_increment'])) {
$auto_increment .= ' AUTO_INCREMENT=' . $tmpres['Auto_increment'] . ' ';
}
if ($show_dates && isset($tmpres['Create_time']) && !empty($tmpres['Create_time'])) {
$schema_create .= '# ' . $GLOBALS['strStatCreateTime'] . ': ' . PMA_localisedDate(strtotime($tmpres['Create_time'])) . $crlf;
$new_crlf = '#' . $crlf . $crlf;
}
if ($show_dates && isset($tmpres['Update_time']) && !empty($tmpres['Update_time'])) {
$schema_create .= '# ' . $GLOBALS['strStatUpdateTime'] . ': ' . PMA_localisedDate(strtotime($tmpres['Update_time'])) . $crlf;
$new_crlf = '#' . $crlf . $crlf;
}
if ($show_dates && isset($tmpres['Check_time']) && !empty($tmpres['Check_time'])) {
$schema_create .= '# ' . $GLOBALS['strStatCheckTime'] . ': ' . PMA_localisedDate(strtotime($tmpres['Check_time'])) . $crlf;
$new_crlf = '#' . $crlf . $crlf;
}
mysql_free_result($result);
}
}
@@ -179,127 +177,58 @@ 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');
} else {
PMA_mysql_query('SET SQL_QUOTE_SHOW_CREATE = 0');
}
$result = PMA_mysql_query('SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table));
if ($result != FALSE && mysql_num_rows($result) > 0) {
$tmpres = PMA_mysql_fetch_array($result);
// Fix for case problems with winwin, thanks to
// Pawe<77> Szczepa<70>ski <pauluz at users.sourceforge.net>
$pos = strpos($tmpres[1], ' (');
// Whether to quote table and fields names or not
if ($use_backquotes) {
PMA_mysql_query('SET SQL_QUOTE_SHOW_CREATE = 1');
} else {
PMA_mysql_query('SET SQL_QUOTE_SHOW_CREATE = 0');
}
$result = PMA_mysql_query('SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table));
if ($result != FALSE && mysql_num_rows($result) > 0) {
$tmpres = PMA_mysql_fetch_array($result);
// Fix for case problems with winwin, thanks to
// Pawe<77> Szczepa<70>ski <pauluz at users.sourceforge.net>
$pos = strpos($tmpres[1], ' (');
// Fix a problem with older versions of mysql
// Find the first opening parenthesys, i.e. that after the name
// of the table
$pos2 = strpos($tmpres[1], '(');
// Old mysql did not insert a space after table name
// in query "show create table ..."!
if ($pos2 != $pos + 1)
{
// This is the real position of the first character after
// the name of the table
$pos = $pos2;
// Old mysql did not even put newlines and indentation...
$tmpres[1] = str_replace(",", ",\n ", $tmpres[1]);
// Fix a problem with older versions of mysql
// Find the first opening parenthesys, i.e. that after the name
// of the table
$pos2 = strpos($tmpres[1], '(');
// Old mysql did not insert a space after table name
// in query "show create table ..."!
if ($pos2 != $pos + 1)
{
// This is the real position of the first character after
// the name of the table
$pos = $pos2;
// Old mysql did not even put newlines and indentation...
$tmpres[1] = str_replace(",", ",\n ", $tmpres[1]);
}
$tmpres[1] = substr($tmpres[1], 0, 13)
. (($use_backquotes) ? PMA_backquote($tmpres[0]) : $tmpres[0])
. substr($tmpres[1], $pos);
$tmpres[1] = str_replace("\n", $crlf, $tmpres[1]);
if (preg_match_all('((,\n[\s]*(CONSTRAINT|FOREIGN[\s]*KEY)[^\n,]+)+)', $tmpres[1], $regs)) {
if (!isset($sql_constraints)) {
$sql_constraints = $crlf . '#' . $crlf
. '# ' . $GLOBALS['strConstraintsForDumped'] . $crlf
. '#' . $crlf;
}
$tmpres[1] = substr($tmpres[1], 0, 13)
. (($use_backquotes) ? PMA_backquote($tmpres[0]) : $tmpres[0])
. substr($tmpres[1], $pos);
$tmpres[1] = str_replace("\n", $crlf, $tmpres[1]);
if (preg_match_all('((,\n[\s]*(CONSTRAINT|FOREIGN[\s]*KEY)[^\n,]+)+)', $tmpres[1], $regs)) {
if (!isset($sql_constraints)) {
$sql_constraints = $crlf . '#' . $crlf
. '# ' . $GLOBALS['strConstraintsForDumped'] . $crlf
. '#' . $crlf;
}
$sql_constraints .= $crlf .'#' . $crlf .'# ' . $GLOBALS['strConstraintsForTable'] . ' ' . PMA_backquote($table) . $crlf . '#' . $crlf;
$sql_constraints .= 'ALTER TABLE ' . PMA_backquote($table) . $crlf
. preg_replace('/(,\n|^)([\s]*)(CONSTRAINT|FOREIGN[\s]*KEY)/', '\1\2ADD \3', substr($regs[0][0], 2))
. ";\n";
$tmpres[1] = preg_replace('((,\n[\s]*(CONSTRAINT|FOREIGN[\s]*KEY)[^\n,]+)+)', '', $tmpres[1]);
}
$schema_create .= $tmpres[1];
$sql_constraints .= $crlf .'#' . $crlf .'# ' . $GLOBALS['strConstraintsForTable'] . ' ' . PMA_backquote($table) . $crlf . '#' . $crlf;
$sql_constraints .= 'ALTER TABLE ' . PMA_backquote($table) . $crlf
. preg_replace('/(,\n|^)([\s]*)(CONSTRAINT|FOREIGN[\s]*KEY)/', '\1\2ADD \3', substr($regs[0][0], 2))
. ";\n";
$tmpres[1] = preg_replace('((,\n[\s]*(CONSTRAINT|FOREIGN[\s]*KEY)[^\n,]+)+)', '', $tmpres[1]);
}
$schema_create .= $tmpres[1];
}
$schema_create .= $auto_increment;
$schema_create .= $auto_increment;
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
@@ -324,7 +253,7 @@ function PMA_getTableComments($db, $table, $crlf, $do_relation = false, $do_comm
global $sql_constraints;
$schema_create = '';
if ($do_comments && $cfgRelation['commwork']) {
if (!($comments_map = PMA_getComments($db, $table))) unset($comments_map);
}
@@ -406,7 +335,7 @@ function PMA_exportStructure($db, $table, $crlf, $error_url, $relation = FALSE,
. '#' . $crlf
. PMA_getTableDef($db, $table, $crlf, $error_url, $dates) . ';' . $crlf
. PMA_getTableComments($db, $table, $crlf, $relation, $comments, $mime);
return PMA_exportOutputHandler($dump);
}
@@ -456,7 +385,7 @@ function PMA_getTableContentFast($db, $table, $crlf, $error_url, $sql_query)
$field_types = PMA_fieldTypes($db,$table,$use_backquotes);
// analyze the query to get the true column names, not the aliases
// (this fixes an undefined index, also if Complete inserts
// (this fixes an undefined index, also if Complete inserts
// are used, we did not get the true column name in case of aliases)
$analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($sql_query));
@@ -496,14 +425,14 @@ function PMA_getTableContentFast($db, $table, $crlf, $error_url, $sql_query)
} else {
$sql_command = 'INSERT';
}
// delayed inserts?
if (isset($GLOBALS['delayed'])) {
$insert_delayed = ' DELAYED';
} else {
$insert_delayed = '';
}
// Sets the scheme
if (isset($GLOBALS['showcolumns'])) {
$fields = implode(', ', $field_set);
@@ -542,13 +471,13 @@ function PMA_getTableContentFast($db, $table, $crlf, $error_url, $sql_query)
// should we make update?
if (isset($GLOBALS['sql_type']) && $GLOBALS['sql_type'] == 'update') {
$insert_line = $schema_insert;
for ($i = 0; $i < $fields_no; $i++) {
if ($i > 0) {
$insert_line .= ', ';
}
$insert_line .= $field_set[$i] . ' = ' . $values[$i];
$insert_line .= $field_set[$i] . ' = ' . $values[$i];
}
} else {
@@ -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);
}
return PMA_getTableContentFast($db, $table, $crlf, $error_url, $sql_query);
} // end of the 'PMA_exportData()' function
?>