From 72998c0df3f0b91376591d38d7171b15a2279ad7 Mon Sep 17 00:00:00 2001 From: e-dschungel Date: Sun, 29 Jan 2017 21:42:37 +0100 Subject: [PATCH 1/4] switched to mysqli_select_db the emulation of mysql_select_db with the USE statement did not quote the table name so table names which need quotation (which contain dashes for example) were not handled correctly the emualtion is not needed, see https://github.com/philip/MySQLConverterTool/issues/20 --- config_overview.php | 4 ++-- inc/functions.php | 4 ++-- inc/functions_dump.php | 6 +++--- inc/functions_global.php | 4 ++-- inc/functions_sql.php | 2 +- inc/home/databases.php | 8 ++++---- inc/mysql.php | 2 +- inc/sqlbrowser/sql_tables.php | 4 ++-- restore.php | 4 ++-- sql.php | 4 ++-- 10 files changed, 21 insertions(+), 21 deletions(-) diff --git a/config_overview.php b/config_overview.php index e04820b..dab1294 100644 --- a/config_overview.php +++ b/config_overview.php @@ -355,7 +355,7 @@ if (isset($_POST['save'])) { if (MSD_mysql_connect()) { - $res=@((bool)mysqli_query($config['dbconnection'], "USE " . $to_add)); + $res=@mysqli_select_db($config['dbconnection'], $to_add)); if (!$res === false) { $databases['Name'][] = $to_add; @@ -1002,4 +1002,4 @@ if (( $showVP ) || ( !isset($databases['Name']) ) || ( isset($databases['name']) echo ''; echo MSDFooter(); $_SESSION['config']=$config; -ob_end_flush(); \ No newline at end of file +ob_end_flush(); diff --git a/inc/functions.php b/inc/functions.php index 099ccef..7fc0f36 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -173,7 +173,7 @@ function SetDefault($load_default = false) $a = 0; for ($i = 0; $i < count($found_dbs); $i++) { $found_db = $found_dbs[$i]; - $use = @((bool)mysqli_query($GLOBALS["___mysqli_ston"], "USE " . $found_db)); + $use = @mysqli_select_db($GLOBALS["___mysqli_ston"], $found_db); if ($use) { if (isset($old_db) && $found_db == $old_db) { $databases['db_selected_index'] = $a; @@ -799,4 +799,4 @@ function db_escape($string) return $string; } -?> \ No newline at end of file +?> diff --git a/inc/functions_dump.php b/inc/functions_dump.php index af03bbd..fb176a5 100644 --- a/inc/functions_dump.php +++ b/inc/functions_dump.php @@ -129,7 +129,7 @@ function get_def($db,$table,$withdata=1) } else $def.="DROP TABLE IF EXISTS `$table`;\n"; - ((bool)mysqli_query($GLOBALS["___mysqli_ston"], "USE " . $db)); + mysqli_select_db($GLOBALS["___mysqli_ston"], $db); $result=mysqli_query($config['dbconnection'], 'SHOW CREATE TABLE `'.$table.'`'); $row=@mysqli_fetch_row($result); if ($row===false) return false; @@ -152,7 +152,7 @@ function get_content($db,$table) $table_ready=0; $query='SELECT * FROM `'.$table.'` LIMIT '.$dump['zeilen_offset'].','.($dump['restzeilen']+1); - ((bool)mysqli_query($GLOBALS["___mysqli_ston"], "USE " . $db)); + mysqli_select_db($GLOBALS["___mysqli_ston"], $db); $result=mysqli_query($config['dbconnection'], $query); $ergebnisse=@mysqli_num_rows($result); if ($ergebnisse!==false) @@ -275,7 +275,7 @@ function ExecuteCommand($when) if (substr(strtolower($cd),0,7)!='system:') { $cad=array(); - @((bool)mysqli_query($GLOBALS["___mysqli_ston"], "USE " . $databases['Name'][$dump['dbindex']])); + mysqli_select_db($GLOBALS["___mysqli_ston"], $databases['Name'][$dump['dbindex']]); if (strpos($cd,';')) { $cad=explode(';',$cd); diff --git a/inc/functions_global.php b/inc/functions_global.php index 0f189fe..1b72a73 100644 --- a/inc/functions_global.php +++ b/inc/functions_global.php @@ -116,7 +116,7 @@ function DBDetailInfo($index) $databases['Detailinfo']['tables'] = $databases['Detailinfo']['records'] = $databases['Detailinfo']['size'] = 0; MSD_mysql_connect(); if (isset($databases['Name'][$index])) { - ((bool)mysqli_query($GLOBALS["___mysqli_ston"], "USE " . $databases['Name'][$index])); + mysqli_select_db($GLOBALS["___mysqli_ston"], $databases['Name'][$index]); $databases['Detailinfo']['Name'] = $databases['Name'][$index]; $res = @mysqli_query( $GLOBALS["___mysqli_ston"], @@ -1420,4 +1420,4 @@ function fetchFileDataFromURL($url) return $in; } -?> \ No newline at end of file +?> diff --git a/inc/functions_sql.php b/inc/functions_sql.php index aba3d00..b0c1c54 100644 --- a/inc/functions_sql.php +++ b/inc/functions_sql.php @@ -226,7 +226,7 @@ function DB_Copy($source, $destination, $drop_source=0, $insert_data=1) return false; } } - ((bool)mysqli_query($GLOBALS["___mysqli_ston"], "USE " . $destination)); + mysqli_select_db($GLOBALS["___mysqli_ston"], $destination); $res=MSD_DoSQL($SQL_Array); if ($drop_source == 1 && $res) MSD_query("DROP DATABASE `$source`;"); return $res; diff --git a/inc/home/databases.php b/inc/home/databases.php index 7143c97..7354cc1 100644 --- a/inc/home/databases.php +++ b/inc/home/databases.php @@ -23,7 +23,7 @@ for ($i=0; $iassign_block_vars('DB_NOT_FOUND',array( 'ROWCLASS' => $rowclass, @@ -73,7 +73,7 @@ for ($i=0; $iassign_block_vars('ROW',array( @@ -102,7 +102,7 @@ if (isset($_GET['dbid'])) $numrows=0; $res=@mysqli_query($GLOBALS["___mysqli_ston"], "SHOW TABLE STATUS FROM `".$databases['Name'][$dbid]."`"); - ((bool)mysqli_query($GLOBALS["___mysqli_ston"], "USE " . $databases['Name'][$dbid])); + mysqli_select_db($GLOBALS["___mysqli_ston"], $databases['Name'][$dbid]); if ($res) $numrows=mysqli_num_rows($res); $tpl->assign_vars(array( 'DB_NAME' => $databases['Name'][$dbid], diff --git a/inc/mysql.php b/inc/mysql.php index bfcfeb6..fa1a289 100644 --- a/inc/mysql.php +++ b/inc/mysql.php @@ -403,7 +403,7 @@ function getDBInfos() } if ($config['optimize_tables_beforedump'] == 1 && $dump['table_offset'] == -1 && $databases['Name'][$dump['dbindex']]!='information_schema') { - ((bool)mysqli_query($GLOBALS["___mysqli_ston"], "USE " . $databases['Name'][$dump['dbindex']])); + mysqli_select_db($GLOBALS["___mysqli_ston"], $databases['Name'][$dump['dbindex']]); $opt = 'OPTIMIZE TABLE `' . $row['Name'] . '`'; $res = mysqli_query($GLOBALS["___mysqli_ston"], 'OPTIMIZE TABLE `' . $row['Name'] . '`'); if ($res === false) { diff --git a/inc/sqlbrowser/sql_tables.php b/inc/sqlbrowser/sql_tables.php index cfc18d9..2c6040d 100644 --- a/inc/sqlbrowser/sql_tables.php +++ b/inc/sqlbrowser/sql_tables.php @@ -278,7 +278,7 @@ if (isset($_POST['newfield_posted'])) $fields_infos=getFieldinfos($databases['Name'][$dbid],$table_edit_name); } } -((bool)mysqli_query($GLOBALS["___mysqli_ston"], "USE " . $databases['Name'][$dbid])); +mysqli_select_db($GLOBALS["___mysqli_ston"], $databases['Name'][$dbid]); $sqlt="SHOW TABLE STATUS FROM `".$databases['Name'][$dbid]."` ;"; $res=MSD_query($sqlt); $anz_tabellen=mysqli_num_rows($res); @@ -592,4 +592,4 @@ if ($table_edit_name!="") echo '
'; echo ''; } -} \ No newline at end of file +} diff --git a/restore.php b/restore.php index 5755f9b..c34f9d4 100644 --- a/restore.php +++ b/restore.php @@ -78,7 +78,7 @@ $pageheader=MSDheader().headline($lang['L_RESTORE']); $aus1=$page_parameter=''; $RestoreFertig=$eingetragen=$dauer=$filegroesse=0; MSD_mysql_connect($restore['dump_encoding'],true,$restore['actual_table']); -@((bool)mysqli_query($GLOBALS["___mysqli_ston"], "USE " . $databases['db_actual'])) or die($lang['L_DB_SELECT_ERROR'].$databases['db_actual'].$lang['L_DB_SELECT_ERROR2']); +@mysqli_select_db($GLOBALS["___mysqli_ston"], $databases['db_actual']) or die($lang['L_DB_SELECT_ERROR'].$databases['db_actual'].$lang['L_DB_SELECT_ERROR2']); // open backup file $restore['filehandle']=($restore['compressed']==1) ? gzopen($config['paths']['backup'].$restore['filename'],'r') : fopen($config['paths']['backup'].$restore['filename'],'r'); @@ -306,4 +306,4 @@ else } echo $complete_page; ob_end_flush(); -?> \ No newline at end of file +?> diff --git a/sql.php b/sql.php index 2eb3438..cd93531 100644 --- a/sql.php +++ b/sql.php @@ -124,7 +124,7 @@ if ($sql_to_display_data==1) if (isset($_POST['tableselect'])&&$_POST['tableselect']!='1') $tablename=$_POST['tableselect']; MSD_mysql_connect(); -((bool)mysqli_query($config['dbconnection'], "USE " . $db)); +mysqli_select_db($config['dbconnection'], $db); ///*** EDIT / UPDATES / INSERTS ***/// ///*** ***/// @@ -295,4 +295,4 @@ function FormHiddenParams() $s.=''; $s.=''; return $s; -} \ No newline at end of file +} From b91ee9e8225da1f445e210fb6662f1c7a733ee76 Mon Sep 17 00:00:00 2001 From: e-dschungel Date: Sun, 29 Jan 2017 23:01:57 +0100 Subject: [PATCH 2/4] fixed quotation in emulation of mysql_list_tables using SHOW TABLES --- inc/functions_imexport.php | 2 +- inc/functions_sql.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/inc/functions_imexport.php b/inc/functions_imexport.php index 7cf7008..b8360df 100644 --- a/inc/functions_imexport.php +++ b/inc/functions_imexport.php @@ -206,7 +206,7 @@ function ImportCreateTable() { global $sql,$lang,$db,$config; $tbl=Array(); - $tabellen=mysqli_query($config['dbconnection'], "SHOW TABLES FROM $db"); + $tabellen=mysqli_query($config['dbconnection'], "SHOW TABLES FROM `$db`"); $num_tables=mysqli_num_rows($tabellen); for ($i=0; $i < $num_tables; $i++) { diff --git a/inc/functions_sql.php b/inc/functions_sql.php index b0c1c54..d9f4052 100644 --- a/inc/functions_sql.php +++ b/inc/functions_sql.php @@ -97,7 +97,7 @@ function Table_ComboBox() function TableComboBox($default='') { global $db,$config,$lang,$nl; - $tabellen=mysqli_query($config['dbconnection'], "SHOW TABLES FROM $db"); + $tabellen=mysqli_query($config['dbconnection'], "SHOW TABLES FROM `$db`"); $num_tables=mysqli_num_rows($tabellen); $s='' . $nl; for ($i=0; $i < $num_tables; $i++) @@ -207,7 +207,7 @@ function DB_Copy($source, $destination, $drop_source=0, $insert_data=1) } } $SQL_Array.="USE `$destination` ;\n"; - $tabellen=mysqli_query($config['dbconnection'], "SHOW TABLES FROM $source"); + $tabellen=mysqli_query($config['dbconnection'], "SHOW TABLES FROM `$source`"); $num_tables=mysqli_num_rows($tabellen); for ($i=0; $i < $num_tables; $i++) { From ceae7607b08142bc4e822d0e6400d22cb1f3f201 Mon Sep 17 00:00:00 2001 From: e-dschungel Date: Mon, 30 Jan 2017 20:12:34 +0100 Subject: [PATCH 3/4] fix closing brace --- config_overview.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config_overview.php b/config_overview.php index dab1294..ce2d13f 100644 --- a/config_overview.php +++ b/config_overview.php @@ -355,7 +355,7 @@ if (isset($_POST['save'])) { if (MSD_mysql_connect()) { - $res=@mysqli_select_db($config['dbconnection'], $to_add)); + $res=@mysqli_select_db($config['dbconnection'], $to_add); if (!$res === false) { $databases['Name'][] = $to_add; From 6c39f2a30613596f150b51c834c16a063250104f Mon Sep 17 00:00:00 2001 From: e-dschungel Date: Mon, 30 Jan 2017 20:15:55 +0100 Subject: [PATCH 4/4] suppress mysqli_connect errors as they are shown later on --- inc/mysql.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/mysql.php b/inc/mysql.php index fa1a289..7bfc695 100644 --- a/inc/mysql.php +++ b/inc/mysql.php @@ -254,7 +254,7 @@ function MSD_mysql_connect($encoding='utf8', $keycheck_off=false, $actual_table= } $port=( isset($config['dbport']) && !empty($config['dbport']) ) ? $config['dbport'] : ini_get("mysqli.default_port"); $socket=( isset($config['dbsocket']) && !empty($config['dbsocket']) ) ? $config['dbsocket'] : ini_get("mysqli.default_socket"); - $config['dbconnection']=($GLOBALS["___mysqli_ston"] = mysqli_connect($config['dbhost'], $config['dbuser'], $config['dbpass'], "", $port, $socket)) or die(SQLError("Error establishing a database connection!", ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)))); + $config['dbconnection']=@($GLOBALS["___mysqli_ston"] = mysqli_connect($config['dbhost'], $config['dbuser'], $config['dbpass'], "", $port, $socket)) or die(SQLError("Error establishing a database connection!", ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)))); if (!defined('MSD_MYSQL_VERSION')) GetMySQLVersion(); if (!isset($config['mysql_standard_character_set']) || $config['mysql_standard_character_set'] == '') get_sql_encodings();