diff --git a/ChangeLog b/ChangeLog
index 748e0a5b9..ebecb5ab0 100755
--- a/ChangeLog
+++ b/ChangeLog
@@ -25,6 +25,13 @@ $Source$
* db_stats.php3, lines 14-12: optimized a bit.
* main.php3, lines 298-299; Documentation.html, lines 694-705: added a FAQ
entry about the logout bug and a link to it at the welcome page.
+ * left.php3: optimized the way tables list is build.
+ * lang/polish.inc.php3: updated thanks to Piotr Roszatycki.
+ * db_create.php3; db_stat.php3; lib.inc.php3; left.php3; main.php3;
+ tbl_alter.php3; tbl_change.php3; tbl_copy.php3; tbl_printview.php3;
+ tbl_properties.php3; tbl_rename.php3; tbl_select.php3: improved the error
+ handling system (it will be easier to debug the script since all the
+ queries will be displayed in case of errors).
2001-08-21 Loïc Chapeaux ' . "\n";
- $edit_link = '' . $GLOBALS['strEdit'] . '';
echo ' ' . $GLOBALS['strSQLQuery'] . ' : ' . "\n";
- echo ' [' . $edit_link . ']' . "\n";
+ if ($is_modify_link) {
+ echo ' ['
+ . '' . $GLOBALS['strEdit'] . ''
+ . ']' . "\n";
+ }
echo '' . "\n" . $query_base . "\n" . '
' . "\n";
echo '
' . "\n" . $error_message . "\n" . '' . "\n"; echo '' . "\n"; - echo '' . $GLOBALS['strBack'] . ''; - + if ($is_back_link) { + $hist = (isset($GLOBALS['btnDrop'])) ? -2 : -1; + echo '' . $GLOBALS['strBack'] . ''; + } echo "\n"; include('./footer.inc.php3'); @@ -284,11 +291,18 @@ if (!defined('__LIB_INC__')){ $server_socket = (empty($cfgServer['socket']) || PHP_INT_VERSION < 30010) ? '' : ':' . $cfgServer['socket']; - $dbh = $connect_func( + $dbh = @$connect_func( $cfgServer['host'] . $server_port . $server_socket, $cfgServer['stduser'], $cfgServer['stdpass'] - ) or mysql_die(); + ); + if ($dbh == FALSE) { + $local_query = $connect_func . '(' + . $cfgServer['host'] . $server_port . $server_socket . ', ' + . $cfgServer['stduser'] . ', ' + . $cfgServer['stdpass'] . ')'; + mysql_die('', $local_query, FALSE, FALSE); + } $PHP_AUTH_USER = str_replace('\'', '\\\'', $PHP_AUTH_USER); $PHP_AUTH_PW = str_replace('\'', '\\\'', $PHP_AUTH_PW); @@ -297,7 +311,7 @@ if (!defined('__LIB_INC__')){ . 'WHERE ' . 'User = \'' . $PHP_AUTH_USER . '\' ' . 'AND Password = PASSWORD(\'' . $PHP_AUTH_PW . '\')'; - $rs = mysql_query($auth_query, $dbh) or mysql_die(); + $rs = mysql_query($auth_query, $dbh) or mysql_die('', $auth_query, FALSE, FALSE); // Invalid login -> relog if (@mysql_numrows($rs) <= 0) { @@ -319,9 +333,11 @@ if (!defined('__LIB_INC__')){ // This maintenance is to fix code to work correctly for // regular expressions. if ($row['Select_priv'] != 'Y') { - $rs = mysql_query('SELECT DISTINCT Db FROM mysql.db WHERE Select_priv = \'Y\' AND User = \'' . $PHP_AUTH_USER . '\'') or mysql_die(); + $local_query = 'SELECT DISTINCT Db FROM mysql.db WHERE Select_priv = \'Y\' AND User = \'' . $PHP_AUTH_USER . '\''; + $rs = mysql_query($local_query) or mysql_die('', $local_query, FALSE, FALSE); if (@mysql_numrows($rs) <= 0) { - $rs = mysql_query('SELECT Db FROM mysql.tables_priv WHERE Table_priv LIKE \'%Select%\' AND User = \'' . $PHP_AUTH_USER . '\'') or mysql_die(); + $local_query = 'SELECT Db FROM mysql.tables_priv WHERE Table_priv LIKE \'%Select%\' AND User = \'' . $PHP_AUTH_USER . '\''; + $rs = mysql_query($local_query) or mysql_die('', $local_query, FALSE, FALSE); if (@mysql_numrows($rs) <= 0) { auth(); } else { @@ -380,11 +396,19 @@ if (!defined('__LIB_INC__')){ $server_socket = (empty($cfgServer['socket']) || PHP_INT_VERSION < 30010) ? '' : ':' . $cfgServer['socket']; - $link = $connect_func( + $link = @$connect_func( $cfgServer['host'] . $server_port . $server_socket, $cfgServer['user'], $cfgServer['password'] - ) or mysql_die(); + ); + if ($link == FALSE) { + $local_query = $connect_func . '(' + . $cfgServer['host'] . $server_port . $server_socket . ', ' + . $cfgServer['user'] . ', ' + . $cfgServer['password'] . ')'; + mysql_die('', $local_query, FALSE, FALSE); + } + } // end server connecting /** @@ -933,9 +957,10 @@ var errorMsg2 = ' get the true type of the // fields. - $result_type = mysql_query('SHOW FIELDS FROM ' . backquote($db) . '.' . backquote($primary->table) . ' LIKE \'' . sql_addslashes($primary->name, TRUE) . '\'') or mysql_die(); + $local_query = 'SHOW FIELDS FROM ' . backquote($db) . '.' . backquote($primary->table) . ' LIKE \'' . sql_addslashes($primary->name, TRUE) . '\''; + $result_type = mysql_query($local_query) or mysql_die('', $local_query); $true_field_type = mysql_fetch_array($result_type); if (eregi('BLOB', $true_field_type['Type'])) { echo '
MySQL ' . $row_version['version'] . ' ' . $strRunning . ' ' . $cfgServer['host']; if (!empty($cfgServer['port'])) { @@ -75,7 +76,7 @@ if ($server > 0) { * Reload mysql (flush privileges) */ if (($server > 0) && isset($mode) && ($mode == 'reload')) { - $result = mysql_query('FLUSH PRIVILEGES'); + $result = mysql_query('FLUSH PRIVILEGES') or mysql_die('', 'FLUSH PRIVILEGES', FALSE); echo '
'; if ($result != 0) { echo $strMySQLReloaded; @@ -165,13 +166,28 @@ if ($server > 0 if ($cfgServer['adv_auth']) { // Get user's rights - if (empty($cfgServer['port'])) { - $stdlink = mysql_connect($cfgServer['host'], $cfgServer['stduser'], $cfgServer['stdpass']); - } else { - $stdlink = mysql_connect($cfgServer['host'] . ':' . $cfgServer['port'], $cfgServer['stduser'], $cfgServer['stdpass']); + $server_port = (empty($cfgServer['port'])) + ? '' + : ':' . $cfgServer['port']; + $server_socket = (empty($cfgServer['socket']) || PHP_INT_VERSION < 30010) + ? '' + : ':' . $cfgServer['socket']; + $stdlink = @mysql_connect( + $cfgServer['host'] . $server_port . $server_socket, + $cfgServer['stduser'], + $cfgServer['stdpass'] + ); + if ($stdlink == FALSE) { + $local_query = $connect_func . '(' + . $cfgServer['host'] . $server_port . $server_socket . ', ' + . $cfgServer['stduser'] . ', ' + . $cfgServer['stdpass'] . ')'; + mysql_die('', $local_query, FALSE, FALSE); } + // Does user have global Create priv? - $rs_usr = mysql_query('SELECT * FROM mysql.user WHERE User = \'' . sql_addslashes($cfgServer['user']) . '\'', $stdlink); + $local_query = 'SELECT * FROM mysql.user WHERE User = \'' . sql_addslashes($cfgServer['user']) . '\''; + $rs_usr = mysql_query($local_query, $stdlink) or mysql_die('', $local_query, FALSE); $result_usr = mysql_fetch_array($rs_usr); $create = ($result_usr['Create_priv'] == 'Y'); $db_to_create = ''; @@ -181,12 +197,21 @@ if ($server > 0 // find, in most cases it's probably the one he just dropped :) // (Note: we only get here after a browser reload, I don't know why) if (!$create) { - if (empty($cfgServer['port'])) { - $userlink = mysql_connect($cfgServer['host'], $cfgServer['user'], $cfgServer['password']) or mysql_die(); - } else { - $userlink = mysql_connect($cfgServer['host'] . ':' . $cfgServer['port'], $cfgServer['user'], $cfgServer['password']) or mysql_die(); + $userlink = @mysql_connect( + $cfgServer['host'] . $server_port . $server_socket, + $cfgServer['user'], + $cfgServer['password'] + ); + if ($userlink == FALSE) { + $local_query = 'mysql_connect(' + . $cfgServer['host'] . $server_port . $server_socket . ', ' + . $cfgServer['user'] . ', ' + . $cfgServer['password'] . ')'; + mysql_die('', $local_query, FALSE, FALSE); } - $rs_usr = mysql_query('SELECT Db FROM mysql.db WHERE User = \'' . sql_addslashes($cfgServer['user']) . '\'', $stdlink); + + $local_query = 'SELECT Db FROM mysql.db WHERE User = \'' . sql_addslashes($cfgServer['user']) . '\''; + $rs_usr = mysql_query($local_query, $stdlink) or mysql_die('', $local_query, FALSE); while ($row = mysql_fetch_array($rs_usr)) { if (!mysql_select_db($row['Db'], $userlink)) { $db_to_create = $row['Db']; diff --git a/tbl_alter.php3 b/tbl_alter.php3 index 9cc2bb325..06471a646 100755 --- a/tbl_alter.php3 +++ b/tbl_alter.php3 @@ -73,9 +73,10 @@ else { } else { $field = sql_addslashes($field, TRUE); } - $result = mysql_query('SHOW FIELDS FROM ' . backquote($db) . '.' . backquote($table) . " LIKE '$field'") or mysql_die(); - $num_fields = mysql_num_rows($result); - $action = 'tbl_alter.php3'; + $local_query = 'SHOW FIELDS FROM ' . backquote($db) . '.' . backquote($table) . " LIKE '$field'"; + $result = mysql_query($local_query) or mysql_die('', $local_query); + $num_fields = mysql_num_rows($result); + $action = 'tbl_alter.php3'; include('./tbl_properties.inc.php3'); } diff --git a/tbl_change.php3 b/tbl_change.php3 index 12c199af6..cd5a72b47 100755 --- a/tbl_change.php3 +++ b/tbl_change.php3 @@ -23,12 +23,14 @@ if (get_magic_quotes_gpc()) { mysql_select_db($db); $table_def = mysql_query('SHOW FIELDS FROM ' . backquote($table)); if (isset($primary_key)) { - $result = mysql_query('SELECT * FROM ' . backquote($table) . ' WHERE ' . $primary_key) or mysql_die(); - $row = mysql_fetch_array($result); + $local_query = 'SELECT * FROM ' . backquote($table) . ' WHERE ' . $primary_key; + $result = mysql_query($local_query) or mysql_die('', $local_query); + $row = mysql_fetch_array($result); } else { - $result = mysql_query('SELECT * FROM ' . backquote($table) . ' LIMIT 1') or mysql_die(); + $local_query = 'SELECT * FROM ' . backquote($table) . ' LIMIT 1'; + $result = mysql_query($local_query) or mysql_die('', $local_query); } diff --git a/tbl_copy.php3 b/tbl_copy.php3 index 3603d4d8e..c6a9ebe37 100755 --- a/tbl_copy.php3 +++ b/tbl_copy.php3 @@ -18,7 +18,7 @@ function my_handler($sql_insert = '') global $sql_insert_data; $sql_insert = ereg_replace('INSERT INTO (`?)' . $table . '(`?)', 'INSERT INTO ' . backquote($new_name), $sql_insert); - $result = mysql_query($sql_insert) or mysql_die(); + $result = mysql_query($sql_insert) or mysql_die('', $sql_insert); $sql_insert_data .= $sql_insert . ';' . "\n"; } // end of the 'my_handler' function @@ -46,7 +46,7 @@ if (isset($new_name) && trim($new_name) != '') { $sql_structure = get_table_def($db, $table, "\n"); $sql_structure = ereg_replace('^CREATE TABLE (`?)' . $table . '(`?)', 'CREATE TABLE ' . backquote($new_name), $sql_structure); - $result = mysql_query($sql_structure) or mysql_die(); + $result = mysql_query($sql_structure) or mysql_die('', $sql_structure); if (isset($sql_query)) { $sql_query .= "\n" . $sql_structure . ';'; } else { @@ -58,7 +58,7 @@ if (isset($new_name) && trim($new_name) != '') { // speedup copy table - staybyte - 22. Juni 2001 if (MYSQL_INT_VERSION >= 32300) { $sql_insert_data = 'INSERT INTO ' . backquote($new_name) . ' SELECT * FROM ' . backquote($table); - $result = mysql_query($sql_insert_data) or mysql_die(); + $result = mysql_query($sql_insert_data) or mysql_die('', $sql_insert_data); } // end MySQL >= 3.23 else { $sql_insert_data = ''; diff --git a/tbl_printview.php3 b/tbl_printview.php3 index b789990ab..e4610be52 100755 --- a/tbl_printview.php3 +++ b/tbl_printview.php3 @@ -23,9 +23,10 @@ mysql_select_db($db); /** * Displays the comments of the table is MySQL >= 3.23 */ -if (MYSQL_INT_VERSION >= 32300) { - $result = mysql_query('SHOW TABLE STATUS LIKE \'' . sql_addslashes($table, TRUE) . '\'') or mysql_die(); - $row = mysql_fetch_array($result); +if (MYSQL_INT_VERSION >= 32300) { + $local_query = 'SHOW TABLE STATUS LIKE \'' . sql_addslashes($table, TRUE) . '\''; + $result = mysql_query($local_query) or mysql_die('', $local_query); + $row = mysql_fetch_array($result); if (!empty($row['Comment'])) { echo $strTableComments . ' : ' . $row['Comment']; } @@ -36,7 +37,8 @@ if (MYSQL_INT_VERSION >= 32300) { * Displays the table structure */ // Gets fields properties -$result = mysql_query('SHOW FIELDS FROM ' . backquote($table)) or mysql_die(); +$local_query = 'SHOW FIELDS FROM ' . backquote($table); +$result = mysql_query($local_query) or mysql_die('', $local_query); ?> @@ -108,7 +110,8 @@ echo "\n"; /** * Displays indexes */ -$result = mysql_query('SHOW KEYS FROM ' . backquote($table)) or mysql_die(); +$local_query = 'SHOW KEYS FROM ' . backquote($table); +$result = mysql_query($local_query) or mysql_die('', $local_query); if (mysql_num_rows($result) > 0) { ?> diff --git a/tbl_properties.php3 b/tbl_properties.php3 index 29b1c76d9..625a324c7 100755 --- a/tbl_properties.php3 +++ b/tbl_properties.php3 @@ -38,7 +38,6 @@ unset($sql_query); /** * Selects the db that will be used during this script execution */ -// mysql_select_db($db) or mysql_die(); $is_db = @mysql_select_db($db); // Not a valid db name -> back to the welcome page if (!$is_db) { @@ -74,21 +73,25 @@ if (MYSQL_INT_VERSION >= 32303) { $comment = stripslashes($comment); } if (empty($prev_comment) || urldecode($prev_comment) != str_replace('"', '"', $comment)) { - $result = mysql_query('ALTER TABLE ' . backquote($table) . ' COMMENT = \'' . sql_addslashes($comment) . '\'') or mysql_die(); + $local_query = 'ALTER TABLE ' . backquote($table) . ' COMMENT = \'' . sql_addslashes($comment) . '\''; + $result = mysql_query($local_query) or mysql_die('', $local_query); } } if (isset($submittype)) { - $result = mysql_query('ALTER TABLE ' . backquote($table) . " TYPE=$tbl_type") or mysql_die(); + $local_query = 'ALTER TABLE ' . backquote($table) . ' TYPE = ' . $tbl_type; + $result = mysql_query($local_query) or mysql_die('', $local_query); } if (isset($submitorderby) && !empty($order_field)) { $order_field = backquote(urldecode($order_field)); - $result = mysql_query('ALTER TABLE ' . backquote($table) . 'ORDER BY ' . $order_field) or mysql_die(); + $local_query = 'ALTER TABLE ' . backquote($table) . 'ORDER BY ' . $order_field; + $result = mysql_query($local_query) or mysql_die('', $local_query); } // Get table type and comments and displays first browse links - $result = mysql_query('SHOW TABLE STATUS LIKE \'' . sql_addslashes($table, TRUE) . '\'') or mysql_die(); - $showtable = mysql_fetch_array($result); - $tbl_type = strtoupper($showtable['Type']); + $local_query = 'SHOW TABLE STATUS LIKE \'' . sql_addslashes($table, TRUE) . '\''; + $result = mysql_query($local_query) or mysql_die('', $local_query); + $showtable = mysql_fetch_array($result); + $tbl_type = strtoupper($showtable['Type']); if (isset($showtable['Rows']) && $showtable['Rows'] > 0) { echo "\n"; @@ -135,8 +138,9 @@ if (MYSQL_INT_VERSION >= 32303) { } // 2. Get table keys and retains them -$result = mysql_query('SHOW KEYS FROM ' . backquote($table)) or mysql_die(); -$primary = ''; +$local_query = 'SHOW KEYS FROM ' . backquote($table); +$result = mysql_query($local_query) or mysql_die('', $local_query); +$primary = ''; while($row = mysql_fetch_array($result)) { $ret_keys[] = $row; if ($row['Key_name'] == 'PRIMARY') { @@ -145,7 +149,8 @@ while($row = mysql_fetch_array($result)) { } // 3. Get fields -$result = mysql_query('SHOW FIELDS FROM ' . backquote($table)) or mysql_die(); +$local_query = 'SHOW FIELDS FROM ' . backquote($table); +$result = mysql_query($local_query) or mysql_die('', $local_query); /** diff --git a/tbl_rename.php3 b/tbl_rename.php3 index 155b99fc6..78ca1b36e 100755 --- a/tbl_rename.php3 +++ b/tbl_rename.php3 @@ -17,9 +17,10 @@ if (isset($new_name) && trim($new_name) != '') { $table = $new_name; include('./header.inc.php3'); mysql_select_db($db); - $result = mysql_query('ALTER TABLE ' . backquote($old_name) . ' RENAME ' . backquote($new_name)) or mysql_die(); - $message = sprintf($strRenameTableOK, $old_name, $table); - $reload = 'true'; + $local_query = 'ALTER TABLE ' . backquote($old_name) . ' RENAME ' . backquote($new_name); + $result = mysql_query($local_query) or mysql_die('', $local_query); + $message = sprintf($strRenameTableOK, $old_name, $table); + $reload = 'true'; } diff --git a/tbl_select.php3 b/tbl_select.php3 index ed980f526..b1c14e7a7 100755 --- a/tbl_select.php3 +++ b/tbl_select.php3 @@ -14,9 +14,9 @@ require('./lib.inc.php3'); */ if (!isset($param) || $param[0] == '') { include('./header.inc.php3'); - $result = mysql_list_fields($db, $table); + $result = @mysql_list_fields($db, $table); if (!$result) { - mysql_die(); + mysql_die('', 'mysql_list_fields(' . $db . ', ' . $table . ')'); } else { // Gets the list and number of fields