diff options
62 files changed, 1086 insertions, 906 deletions
@@ -5,6 +5,35 @@ phpMyAdmin - Changelog $Id$ $Source$ +2004-01-22 Alexander M. Turek <innocenteyes@derrabus.de> + * libraries/dbi/mysqli.dbi.lib.php: Experimental new MySQLi library. + * browse_foreigners.php, db_create.php, db_datadict.php, + db_details_common.php, db_details_db_info.php, db_details_qbe.php, + db_details_structure.php, db_printview.php, export.php, ldi_table.php, + left.php, main.php, mult_submits.php, pdf_pages.php, pdf_schema.php, + querywindow.php, read_dump.php, server_common.inc.php, + server_privileges.php, server_processlist.php, server_status.php, + server_variables.php, sql.php, tbl_addfield.php, tbl_alter.php, + tbl_change.php, tbl_create.php, tbl_index.php, tbl_move_copy.php, + tbl_printview.php, tbl_properties.inc.php, tbl_properties_operations.php, + tbl_properties_table_info.php, tbl_query_box.php, tbl_relation.php, + tbl_rename.php, tbl_replace.php, tbl_select.php, + transformation_wrapper.php, user_password.php, libraries/bookmark.lib.php, + libraries/common.lib.php, libraries/db_table_exists.lib.php, + libraries/display_tbl:lib.php, libraries/get_foreign.lib.php, + libraries/mysql_charsets.lib.php, libraries/relation.lib.php, + libraries/transformations.lib.php, libraries/auth/config.auth.lib.php, + libraries/auth/cookie.auth.lib.php, libraries/export/*.php: + - Removed most remaining calls to old mysql_wrappers library; + - Small optimizations and XHTML fixes. + * libraries/database_interface.lib.php, libraries/dbi/mysql.dbi.lib.php: + - Moved PMA_DBI_get_dblist() definition to database_interface.lib; + - Fixed "undefined constant" warning (bug #881637); + - Added new functions: PMA_DBI_select_db(), PMA_DBI_get_fields(), + PMA_DBI_get_fields_meta(); + - Bypassing charset conversion code for MySQL >= 4.1 experimentally. + * Documentation.html: Changed my email address. + 2004-01-21 Michal Cihar <thesiswritten@cihar.com> * lang/czech: Fixed unclear message. diff --git a/Documentation.html b/Documentation.html index 58021e1b15..17ff9e0fc5 100755 --- a/Documentation.html +++ b/Documentation.html @@ -2417,7 +2417,7 @@ To create a new, empty mimetype please see libraries/transformations/template_ge phpMyAdmin provides experimental support for MySQL 4.1 and 5.0. That means that although you can assign character sets to a table or field, phpMyAdmin will not recode the data when inserting or extracting it. - Instead, it will still use the character set you specified for the MySQL + Instead, it will still use the character set you specified for the MySQL onnection.<br /> When compiling php, we strongly recommend that you manually link the MySQL extension to a MySQL client library of at least the same version since the @@ -3522,13 +3522,13 @@ To create a new, empty mimetype please see libraries/transformations/template_ge </p> <h4> [6.22] Bookmarks: Can I execute a default bookmark automatically - when entering Browse mode for a table? + when entering Browse mode for a table? </h4> <p> Yes. If a bookmark has the same label as a table name, it will be - executed. + executed. </p> - + <a name="faqproject"></a><br /> <h3>[7. phpMyAdmin project]</h3> @@ -3790,7 +3790,7 @@ CREDITS, in chronological order * main author of the version 2.1.0.1 * bugfixes -- Alexander M. Turek <derrabus_at_gmx.de> +- Alexander M. Turek <me_at_derrabus.de> * XML exports * MySQL 4 related features * various features and fixes diff --git a/browse_foreigners.php b/browse_foreigners.php index 50715033b2..e7e1c0fd7c 100644 --- a/browse_foreigners.php +++ b/browse_foreigners.php @@ -142,31 +142,31 @@ if (isset($disp) && $disp) { function dimsort($arrayA, $arrayB) { $keyA = key($arrayA); $keyB = key($arrayB); - + if ($arrayA[$keyA] == $arrayB[$keyB]) { return 0; } - + return ($arrayA[$keyA] < $arrayB[$keyB]) ? -1 : 1; } $mysql_key_relrow = array(); $mysql_val_relrow = array(); $count = 0; - while ($relrow = @PMA_mysql_fetch_array($disp)) { + while ($relrow = @PMA_DBI_fetch_assoc($disp)) { if ($foreign_display != FALSE) { $val = $relrow[$foreign_display]; } else { $val = ''; } - + $mysql_key_relrow[$count] = array($relrow[$foreign_field] => $val); $mysql_val_relrow[$count] = array($val => $relrow[$foreign_field]); $count++; } - + usort($mysql_val_relrow, 'dimsort'); - + $hcount = 0; for ($i = 0; $i < $count; $i++) { $hcount++; diff --git a/db_create.php b/db_create.php index 1e60540045..3af8da4923 100644 --- a/db_create.php +++ b/db_create.php @@ -29,7 +29,7 @@ if (isset($db_charset) && isset($mysql_charsets) && in_array($db_charset, $mysql } $sql_query .= ';'; -$result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', $sql_query, FALSE, $err_url); +$result = PMA_DBI_query($sql_query); /** diff --git a/db_datadict.php b/db_datadict.php index 56194b4723..3498b39386 100644 --- a/db_datadict.php +++ b/db_datadict.php @@ -52,15 +52,11 @@ if ($cfgRelation['commwork']) { /** * Selects the database and gets tables names */ -PMA_mysql_select_db($db); -$sql = 'SHOW TABLES FROM ' . PMA_backquote($db); -$rowset = @PMA_mysql_query($sql); +PMA_DBI_select_db($db); +$rowset = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($db) . ';'); -if (!$rowset) { - exit(); -} $count = 0; -while ($row = PMA_mysql_fetch_array($rowset)) { +while ($row = PMA_DBI_fetch_assoc($rowset)) { $myfieldname = 'Tables_in_' . htmlspecialchars($db); $table = $row[$myfieldname]; if ($cfgRelation['commwork']) { @@ -76,21 +72,17 @@ while ($row = PMA_mysql_fetch_array($rowset)) { * Gets table informations */ // The 'show table' statement works correct since 3.23.03 - $local_query = 'SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\''; - $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url); - $showtable = PMA_mysql_fetch_array($result); + $result = PMA_DBI_query('SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\''); + $showtable = PMA_DBI_fetch_assoc($result); $num_rows = (isset($showtable['Rows']) ? $showtable['Rows'] : 0); $show_comment = (isset($showtable['Comment']) ? $showtable['Comment'] : ''); - if ($result) { - PMA_DBI_free_result($result); - } + PMA_DBI_free_result($result); /** * Gets table keys and retains them */ - $local_query = 'SHOW KEYS FROM ' . PMA_backquote($table); - $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url); + $result = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';'); $primary = ''; $indexes = array(); $lastIndex = ''; @@ -98,7 +90,7 @@ while ($row = PMA_mysql_fetch_array($rowset)) { $indexes_data = array(); $pk_array = array(); // will be use to emphasis prim. keys in the table // view - while ($row = PMA_mysql_fetch_array($result)) { + while ($row = PMA_DBI_fetch_assoc($result)) { // Backups the list of primary keys if ($row['Key_name'] == 'PRIMARY') { $primary .= $row['Column_name'] . ', '; @@ -133,8 +125,7 @@ while ($row = PMA_mysql_fetch_array($rowset)) { /** * Gets fields properties */ - $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table); - $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url); + $result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';'); $fields_cnt = PMA_DBI_num_rows($result); // Check if we can use Relations (Mike Beck) if (!empty($cfgRelation['relation'])) { @@ -190,7 +181,7 @@ while ($row = PMA_mysql_fetch_array($rowset)) { <?php $i = 0; - while ($row = PMA_mysql_fetch_array($result)) { + while ($row = PMA_DBI_fetch_assoc($result)) { $bgcolor = ($i % 2) ?$cfg['BgcolorOne'] : $cfg['BgcolorTwo']; $i++; diff --git a/db_details_common.php b/db_details_common.php index fe132485e4..866f866564 100644 --- a/db_details_common.php +++ b/db_details_common.php @@ -25,7 +25,7 @@ $err_url = $cfg['DefaultTabDatabase'] . '?' . PMA_generate_common_url($db); if (!isset($is_db) || !$is_db) { // Not a valid db name -> back to the welcome page if (!empty($db)) { - $is_db = @PMA_mysql_select_db($db); + $is_db = PMA_DBI_select_db($db); } if (empty($db) || !$is_db) { header('Location: ' . $cfg['PmaAbsoluteUri'] . 'main.php?' . PMA_generate_common_url('', '', '&') . (isset($message) ? '&message=' . urlencode($message) : '') . '&reload=1'); @@ -38,7 +38,7 @@ if (!isset($is_db) || !$is_db) { */ if (isset($submitcharset) && PMA_MYSQL_INT_VERSION >= 40101) { $sql_query = 'ALTER DATABASE ' . PMA_backquote($db) . ' DEFAULT CHARACTER SET ' . $db_charset; - $result = PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query, '', $err_url); + $result = PMA_DBI_query($sql_query); $message = $strSuccess; } diff --git a/db_details_db_info.php b/db_details_db_info.php index 1087230fae..21a6ecdd64 100644 --- a/db_details_db_info.php +++ b/db_details_db_info.php @@ -18,11 +18,10 @@ PMA_checkParameters(array('db')); $tables = array(); // Special speedup for newer MySQL Versions (in 4.0 format changed) if ($cfg['SkipLockedTables'] == TRUE) { - $local_query = 'SHOW OPEN TABLES FROM ' . PMA_backquote($db); - $db_info_result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url_0); + $db_info_result = PMA_DBI_query('SHOW OPEN TABLES FROM ' . PMA_backquote($db) . ';'); // Blending out tables in use if ($db_info_result != FALSE && PMA_DBI_num_rows($db_info_result) > 0) { - while ($tmp = PMA_mysql_fetch_row($db_info_result)) { + while ($tmp = PMA_DBI_fetch_row($db_info_result)) { // if in use memorize tablename if (preg_match('@in_use=[1-9]+@i', $tmp[1])) { $sot_cache[$tmp[0]] = TRUE; @@ -31,14 +30,12 @@ if ($cfg['SkipLockedTables'] == TRUE) { PMA_DBI_free_result($db_info_result); if (isset($sot_cache)) { - $local_query = 'SHOW TABLES FROM ' . PMA_backquote($db); - $db_info_result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url_0); + $db_info_result = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($db) . ';'); if ($db_info_result != FALSE && PMA_DBI_num_rows($db_info_result) > 0) { - while ($tmp = PMA_mysql_fetch_row($db_info_result)) { + while ($tmp = PMA_DBI_fetch_row($db_info_result)) { if (!isset($sot_cache[$tmp[0]])) { - $local_query = 'SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \'' . addslashes($tmp[0]) . '\''; - $sts_result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url_0); - $sts_tmp = PMA_mysql_fetch_array($sts_result); + $sts_result = PMA_DBI_query('SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \'' . addslashes($tmp[0]) . '\';'); + $sts_tmp = PMA_DBI_fetch_assoc($sts_result); $tables[] = $sts_tmp; } else { // table in use $tables[] = array('Name' => $tmp[0]); @@ -51,13 +48,13 @@ if ($cfg['SkipLockedTables'] == TRUE) { } } if (!isset($sot_ready)) { - $local_query = 'SHOW TABLE STATUS FROM ' . PMA_backquote($db); - $db_info_result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url_0); + $db_info_result = PMA_DBI_query('SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ';'); if ($db_info_result != FALSE && PMA_DBI_num_rows($db_info_result) > 0) { - while ($sts_tmp = PMA_mysql_fetch_array($db_info_result)) { + while ($sts_tmp = PMA_DBI_fetch_assoc($db_info_result)) { $tables[] = $sts_tmp; } PMA_DBI_free_result($db_info_result); + unset($db_info_result); } } $num_tables = (isset($tables) ? count($tables) : 0); diff --git a/db_details_links.php b/db_details_links.php index 61257662e7..dd5e7771c3 100644 --- a/db_details_links.php +++ b/db_details_links.php @@ -37,8 +37,8 @@ else { // Drop link if allowed if (!$cfg['AllowUserDropDatabase']) { // Check if the user is a Superuser - $links_result = @PMA_mysql_query('USE mysql'); - $cfg['AllowUserDropDatabase'] = (!PMA_mysql_error()); + $cfg['AllowUserDropDatabase'] = PMA_DBI_select_db('mysql'); + PMA_DBI_select_db($db); } if ($cfg['AllowUserDropDatabase']) { $lnk5 = 'sql.php'; diff --git a/db_details_qbe.php b/db_details_qbe.php index f9d88efa0c..8b2f3a7189 100644 --- a/db_details_qbe.php +++ b/db_details_qbe.php @@ -114,7 +114,7 @@ if ($row < 0) { /** * Prepares the form */ -$tbl_result = PMA_mysql_list_tables($db); +$tbl_result = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($db) . ';'); $tbl_result_cnt = PMA_DBI_num_rows($tbl_result); $i = 0; $k = 0; @@ -129,8 +129,8 @@ if (!empty($TableList)) { // The tables list gets from MySQL while ($i < $tbl_result_cnt) { - $tbl = PMA_mysql_tablename($tbl_result, $i); - $fld_results = @PMA_mysql_list_fields_alternate($db, $tbl) or PMA_mysqlDie(PMA_mysql_error(), 'PMA_mysql_list_fields_alternate(' . $db . ', ' . $tbl . ')', FALSE, $err_url); + list($tbl) = PMA_DBI_fetch_row($tbl_result); + $fld_results = PMA_DBI_get_fields($db, $tbl); $fld_results_cnt = ($fld_results) ? count($fld_results) : 0; $j = 0; @@ -779,12 +779,11 @@ if (isset($Field) && count($Field) > 0) { // ( When the control user is the same as the normal user // because he is using one of his databases as pmadb, // the last db selected is not always the one where we need to work) - PMA_mysql_select_db($db); + PMA_DBI_select_db($db); foreach($tab_all AS $tab) { - $ind_qry = 'SHOW INDEX FROM ' . PMA_backquote($tab); - $ind_rs = PMA_mysql_query($ind_qry); - while ($ind = PMA_mysql_fetch_array($ind_rs)) { + $ind_rs = PMA_DBI_query('SHOW INDEX FROM ' . PMA_backquote($tab) . ';'); + while ($ind = PMA_DBI_fetch_assoc($ind_rs)) { $col1 = $tab . '.' . $ind['Column_name']; if (isset($col_all[$col1])) { if ($ind['non_unique'] == 0) { @@ -853,10 +852,12 @@ if (isset($Field) && count($Field) > 0) { if ($checked_tables[$tab] != 1 ) { $rows_qry = 'SELECT COUNT(1) AS anz ' . 'FROM ' . PMA_backquote($tab); - $rows_rs = PMA_mysql_query($rows_qry); - while ($res = PMA_mysql_fetch_array($rows_rs)) { + $rows_rs = PMA_DBI_query($rows_qry); + while ($res = PMA_DBI_fetch_assoc($rows_rs)) { $tsize[$tab] = $res['anz']; } + PMA_DBI_free_result($rows_rs); + unset($rows_rs); $checked_tables[$tab] = 1; } $csize[$tab] = $tsize[$tab]; @@ -928,16 +929,10 @@ if (isset($Field) && count($Field) > 0) { . ' AND ' . $to . '_db = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND ' . $from . '_table IN ' . $in_know . ' AND ' . $to . '_table IN ' . $in_left; - if (isset($dbh)) { - PMA_mysql_select_db($cfgRelation['db'], $dbh); - $relations = @PMA_mysql_query($rel_query, $dbh) or PMA_mysqlDie(PMA_mysql_error($dbh), $rel_query, '', $err_url_0); - PMA_mysql_select_db($db, $dbh); - } else { - PMA_mysql_select_db($cfgRelation['db']); - $relations = @PMA_mysql_query($rel_query) or PMA_mysqlDie('', $rel_query, '', $err_url_0); - PMA_mysql_select_db($db); - } - while ($row = PMA_mysql_fetch_array($relations)) { + PMA_DBI_select_db($cfgRelation['db'], $dbh); + $relations = @PMA_DBI_query($rel_query, $dbh); + PMA_DBI_select_db($db, $dbh); + while ($row = PMA_DBI_fetch_assoc($relations)) { $found_table = $row[$to . '_table']; if (isset($tab_left[$found_table])) { $fromclause .= "\n" . ' LEFT JOIN ' diff --git a/db_details_structure.php b/db_details_structure.php index 67071096b8..173902b750 100644 --- a/db_details_structure.php +++ b/db_details_structure.php @@ -156,8 +156,8 @@ else { $tooltip_truename = array(); $tooltip_aliasname = array(); - $result = PMA_mysql_query('SHOW TABLE STATUS FROM ' . PMA_backquote($db)); - while ($tmp = PMA_mysql_fetch_array($result)) { + $result = PMA_DBI_query('SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ';'); + while ($tmp = PMA_DBI_fetch_assoc($result)) { $tooltip_truename[$tmp['Name']] = ($cfg['ShowTooltipAliasTB'] ? (!empty($tmp['Comment']) ? $tmp['Comment'] . ' ' : $tmp['Name']) : $tmp['Name']); $tooltip_aliasname[$tmp['Name']] = ($cfg['ShowTooltipAliasTB'] ? $tmp['Name'] : (!empty($tmp['Comment']) ? $tmp['Comment'] . ' ' : '')); if (isset($tmp['Create_time']) && !empty($tmp['Create_time'])) { @@ -345,9 +345,10 @@ else { $local_query = 'SELECT COUNT(*) AS count FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table); - $table_info_result = PMA_mysql_query($local_query) - or PMA_mysqlDie('', $local_query, '', $err_url_0); - $row_count = PMA_mysql_result($table_info_result, 0, 'count'); + $table_info_result = PMA_DBI_query($local_query); + list($row_count) = PMA_DBI_fetch_row($table_info_result); + PMA_DBI_free_result($table_info_result); + unset($table_info_result); $sum_entries += $row_count; } else { $row_count = $sts_data['Rows']; @@ -660,10 +661,12 @@ if ($cfgRelation['pdfwork'] && $num_tables > 0) { <?php echo $strPageNumber; ?> <select name="pdf_page_number"> <?php - while ($pages = @PMA_mysql_fetch_array($test_rs)) { + while ($pages = @PMA_DBI_fetch_assoc($test_rs)) { echo "\n" . ' ' . '<option value="' . $pages['page_nr'] . '">' . $pages['page_nr'] . ': ' . $pages['page_descr'] . '</option>'; } // end while + PMA_DBI_free_result($test_rs); + unset($test_rs); echo "\n"; ?> </select><br /> diff --git a/db_printview.php b/db_printview.php index 316f8b4d95..cb46794171 100644 --- a/db_printview.php +++ b/db_printview.php @@ -32,46 +32,45 @@ $cfgRelation = PMA_getRelationsParam(); // staybyte: speedup view on locked tables - 11 June 2001 // Special speedup for newer MySQL Versions (in 4.0 format changed) if ($cfg['SkipLockedTables'] == TRUE) { - $local_query = 'SHOW OPEN TABLES FROM ' . PMA_backquote($db); - $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url); + $result = PMA_DBI_query('SHOW OPEN TABLES FROM ' . PMA_backquote($db) . ';'); // Blending out tables in use if ($result != FALSE && PMA_DBI_num_rows($result) > 0) { - while ($tmp = PMA_mysql_fetch_array($result)) { + while ($tmp = PMA_DBI_fetch_row($result)) { // if in use memorize tablename if (preg_match('@in_use=[1-9]+@i', $tmp[0])) { $sot_cache[$tmp[0]] = TRUE; } } PMA_DBI_free_result($result); + unset($result); if (isset($sot_cache)) { - $local_query = 'SHOW TABLES FROM ' . PMA_backquote($db); - $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url); + $result = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($db) . ';'); if ($result != FALSE && PMA_DBI_num_rows($result) > 0) { - while ($tmp = PMA_mysql_fetch_array($result)) { + while ($tmp = PMA_DBI_fetch_row($result)) { if (!isset($sot_cache[$tmp[0]])) { - $local_query = 'SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \'' . addslashes($tmp[0]) . '\''; - $sts_result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url); - $sts_tmp = PMA_mysql_fetch_array($sts_result); + $sts_result = PMA_DBI_query('SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \'' . addslashes($tmp[0]) . '\';'); + $sts_tmp = PMA_DBI_fetch_assoc($sts_result); $tables[] = $sts_tmp; } else { // table in use $tables[] = array('Name' => $tmp[0]); } } PMA_DBI_free_result($result); + unset($result); $sot_ready = TRUE; } } } } if (!isset($sot_ready)) { - $local_query = 'SHOW TABLE STATUS FROM ' . PMA_backquote($db); - $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url); - if ($result != FALSE && PMA_DBI_num_rows($result) > 0) { - while ($sts_tmp = PMA_mysql_fetch_array($result)) { + $result = PMA_DBI_query('SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ';'); + if (PMA_DBI_num_rows($result) > 0) { + while ($sts_tmp = PMA_DBI_fetch_assoc($result)) { $tables[] = $sts_tmp; } PMA_DBI_free_result($result); + unset($res); } } $num_tables = (isset($tables) ? count($tables) : 0); diff --git a/db_search.php b/db_search.php index 48fe2be494..f43774489c 100644 --- a/db_search.php +++ b/db_search.php @@ -20,14 +20,8 @@ $url_query .= '&goto=db_search.php'; /** * Get the list of tables from the current database */ -$list_tables = PMA_mysql_list_tables($db); -$num_tables = ($list_tables ? PMA_DBI_num_rows($list_tables) : 0); -for ($i = 0; $i < $num_tables; $i++) { - $tables[] = PMA_mysql_tablename($list_tables, $i); -} -if ($num_tables) { - PMA_DBI_free_result($list_tables); -} +$tables = PMA_DBI_get_tables($db); +$num_tables = count($tables); /** @@ -63,17 +57,14 @@ if (isset($submit_search)) { $sqlstr_delete = 'DELETE'; // Fields to select - $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($GLOBALS['db']); - $res = @PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, FALSE, $err_url); - $res_cnt = ($res ? PMA_DBI_num_rows($res) : 0); - for ($i = 0; $i < $res_cnt; $i++) { - $tblfields[] = PMA_backquote(PMA_mysql_result($res, $i, 'field')); - } // end if + $res = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($GLOBALS['db']) . ';'); + while (list($current) = PMA_DBI_fetch_row($res)) { + $tblfields[] = PMA_backquote($current); + } // while + PMA_DBI_free_result($res); + unset($current, $res); $sqlstr_fieldstoselect = ' ' . implode(', ', $tblfields); $tblfields_cnt = count($tblfields); - if ($res) { - PMA_DBI_free_result($res); - } // Table to use $sqlstr_from = ' FROM ' . PMA_backquote($GLOBALS['db']) . '.' . PMA_backquote($table); @@ -187,14 +178,10 @@ if (isset($submit_search)) { $newsearchsqls = PMA_getSearchSqls($onetable, $search_str, $search_option); // Executes the "COUNT" statement - $local_query = $newsearchsqls['select_count']; - $res = @PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, FALSE, $err_url); - if ($res) { - $res_cnt = PMA_mysql_result($res, 0, 'count'); - PMA_DBI_free_result($res); - } else { - $res_cnt = 0; - } // end if... else ... + $res = PMA_DBI_query($newsearchsqls['select_count']); + $res_cnt = PMA_DBI_fetch_assoc($res); + $res_cnt = $res_cnt['count']; + PMA_DBI_free_result($res); $num_search_result_total = $res_cnt; echo ' <!-- Search results in table ' . $onetable . ' (' . $res_cnt . ') -->' . "\n" @@ -226,14 +213,11 @@ if (isset($submit_search)) { $newsearchsqls = PMA_getSearchSqls($table_select[$i], $search_str, $search_option); // Executes the "COUNT" statement - $local_query = $newsearchsqls['select_count']; - $res = @PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, FALSE, $err_url); - if ($res) { - $res_cnt = PMA_mysql_result($res, 0, 'count'); - PMA_DBI_free_result($res); - } else { - $res_cnt = 0; - } // end if... else ... + $res = PMA_DBI_query($newsearchsqls['select_count']); + $res_cnt = PMA_DBI_fetch_assoc($res); + $res_cnt = $res_cnt['count']; + PMA_DBI_free_result($res); + unset($res); $num_search_result_total += $res_cnt; echo ' <!-- Search results in table ' . $table_select[$i] . ' (' . $res_cnt . ') -->' . "\n" diff --git a/export.php b/export.php index 7ba6d7fbf5..de59b3e5bb 100644 --- a/export.php +++ b/export.php @@ -309,8 +309,8 @@ if (!$save_on_server) { // Check if we have something to export if ($export_type == 'database') { - $tables = PMA_mysql_list_tables($db); - $num_tables = ($tables) ? @PMA_DBI_num_rows($tables) : 0; + $tables = PMA_DBI_get_tables($db); + $num_tables = count($tables); if ($num_tables == 0) { $message = $strNoTablesFound; $js_to_run = 'functions.js'; @@ -369,15 +369,15 @@ if ($export_type == 'server') { || !isset($tmp_select)) { PMA_exportDBHeader($current_db); PMA_exportDBCreate($current_db); - $tables = PMA_mysql_list_tables($current_db); - $num_tables = ($tables) ? @PMA_DBI_num_rows($tables) : 0; - $i = 0; - while ($i < $num_tables) { - $table = PMA_mysql_tablename($tables, $i); + $tables = PMA_DBI_get_tables($current_db); + foreach ($tables as $table) { $local_query = 'SELECT * FROM ' . PMA_backquote($current_db) . '.' . PMA_backquote($table); - if (isset($GLOBALS[$what . '_structure'])) PMA_exportStructure($current_db, $table, $crlf, $err_url, $do_relation, $do_comments, $do_mime, $do_dates); - if (isset($GLOBALS[$what . '_data'])) PMA_exportData($current_db, $table, $crlf, $err_url, $local_query); - $i++; + if (isset($GLOBALS[$what . '_structure'])) { + PMA_exportStructure($current_db, $table, $crlf, $err_url, $do_relation, $do_comments, $do_mime, $do_dates); + } + if (isset($GLOBALS[$what . '_data'])) { + PMA_exportData($current_db, $table, $crlf, $err_url, $local_query); + } } PMA_exportDBFooter($current_db); } @@ -389,16 +389,18 @@ if ($export_type == 'server') { $tmp_select = '|' . $tmp_select . '|'; } $i = 0; - while ($i < $num_tables) { - $table = PMA_mysql_tablename($tables, $i); + foreach ($tables as $table) { $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table); if ((isset($tmp_select) && strpos(' ' . $tmp_select, '|' . $table . '|')) || !isset($tmp_select)) { - if (isset($GLOBALS[$what . '_structure'])) PMA_exportStructure($db, $table, $crlf, $err_url, $do_relation, $do_comments, $do_mime, $do_dates); - if (isset($GLOBALS[$what . '_data'])) PMA_exportData($db, $table, $crlf, $err_url, $local_query); + if (isset($GLOBALS[$what . '_structure'])) { + PMA_exportStructure($db, $table, $crlf, $err_url, $do_relation, $do_comments, $do_mime, $do_dates); + } + if (isset($GLOBALS[$what . '_data'])) { + PMA_exportData($db, $table, $crlf, $err_url, $local_query); + } } - $i++; } PMA_exportDBFooter($db); } else { @@ -415,7 +417,7 @@ if ($export_type == 'server') { if (!empty($sql_query)) { $local_query = $sql_query . $add_query; - PMA_mysql_select_db($db); + PMA_DBI_select_db($db); } else { $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . $add_query; } diff --git a/ldi_table.php b/ldi_table.php index 3d3a6e08c7..d9f837cf27 100644 --- a/ldi_table.php +++ b/ldi_table.php @@ -152,15 +152,15 @@ if (PMA_MYSQL_INT_VERSION < 32349) { } if (PMA_MYSQL_INT_VERSION > 40003) { - $tmp_query = "SHOW VARIABLES LIKE 'local\\_infile'"; - $result = PMA_mysql_query($tmp_query); + $result = PMA_DBI_try_query('SHOW VARIABLES LIKE \'local\\_infile\';'); if ($result != FALSE && PMA_DBI_num_rows($result) > 0) { - $tmp = PMA_mysql_fetch_row($result); + $tmp = PMA_DBI_fetch_row($result); if ($tmp[1] == 'ON') { $local_option_selected = TRUE; } } PMA_DBI_free_result($result); + unset($result); } ?> @@ -406,7 +406,7 @@ if ($num_dbs > 1) { if (!empty($db_start) && $db == $db_start) { $selected_db = $j; } - $tables = @PMA_mysql_list_tables($db); + $tables = PMA_DBI_try_query('SHOW TABLES FROM ' . PMA_backquote($db) . ';'); $num_tables = ($tables) ? @PMA_DBI_num_rows($tables) : 0; $common_url_query = PMA_generate_common_url($db); if ($num_tables) { @@ -421,8 +421,8 @@ if ($num_dbs > 1) { && (!$cfg['LeftFrameLight'] || $selected_db == $j)) { $tooltip = array(); $tooltip_name = array(); - $result = PMA_mysql_query('SHOW TABLE STATUS FROM ' . PMA_backquote($db)); - while ($tmp = PMA_mysql_fetch_array($result)) { + $result = PMA_DBI_try_query('SHOW TABLE STATUS FROM ' . PMA_backquote($db)); + while ($tmp = PMA_DBI_fetch_assoc($result)) { $tooltip_name[$tmp['Name']] = (!empty($tmp['Comment']) ? $tmp['Comment'] . ' ' : ''); $tmp['Comment'] = ($cfg['ShowTooltipAliasTB'] ? $tmp['Name'] : $tmp['Comment']); @@ -471,8 +471,7 @@ if ($num_dbs > 1) { <?php // Displays the list of tables from the current database $tablestack = array(); - for ($t = 0; $t < $num_tables; $t++) { - $table = PMA_mysql_tablename($tables, $t); + while (list($table) = PMA_DBI_fetch_row($tables)) { $alias = (!empty($tooltip_name) && isset($tooltip_name[$table])) ? htmlspecialchars($tooltip_name[$table]) : ''; @@ -512,7 +511,7 @@ if ($num_dbs > 1) { $tablestack['']['pma_name'][] = $table; $tablestack['']['pma_list_item'][] = $list_item; } - } // end for $t (tables list) + } // end while (tables list) PMA_nestedSet($j, $tablestack); ?> @@ -530,8 +529,7 @@ if ($num_dbs > 1) { // Builds the databases' names list if (!empty($db_start) && $db == $db_start) { // Gets the list of tables from the current database - for ($t = 0; $t < $num_tables; $t++) { - $table = PMA_mysql_tablename($tables, $t); + while (list($table) = PMA_DBI_fetch_row($tables)) { $url_title = (!empty($tooltip) && isset($tooltip[$table])) ? htmlentities($tooltip[$table]) : ''; @@ -548,7 +546,7 @@ if ($num_dbs > 1) { } else { $table_list .= ' <a class="tblItem" id="tbl_' . md5($table) . '" title="' . $url_title . '" target="phpmain' . $hash . '" href="' . $cfg['DefaultTabTable'] . '?' . $common_url_query . '&table=' . urlencode($table) . '">' . ($alias != '' && $cfg['ShowTooltipAliasTB'] ? $alias : htmlspecialchars($table)) . '</a></nobr><br />' . "\n"; } - } // end for $t (tables list) + } // end while (tables list) if (!$table_list) { $table_list = ' <br /><br />' . "\n" @@ -618,7 +616,7 @@ if ($num_dbs > 1) { // Case where only one database has to be displayed else if ($num_dbs == 1) { $db = $dblist[0]; - $tables = @PMA_mysql_list_tables($db); + $tables = PMA_DBI_try_query('SHOW TABLES FROM ' . PMA_backquote($db) . ';'); $num_tables = ($tables) ? @PMA_DBI_num_rows($tables) : 0; $common_url_query = PMA_generate_common_url($db); if ($num_tables) { @@ -632,8 +630,8 @@ else if ($num_dbs == 1) { && $num_tables) { $tooltip = array(); $tooltip_name = array(); - $result = PMA_mysql_query('SHOW TABLE STATUS FROM ' . PMA_backquote($db)); - while ($tmp = PMA_mysql_fetch_array($result)) { + $result = PMA_DBI_try_query('SHOW TABLE STATUS FROM ' . PMA_backquote($db)); + while ($tmp = PMA_DBI_fetch_assoc($result)) { $tooltip_name[$tmp['Name']] = (!empty($tmp['Comment']) ? $tmp['Comment'] . ' ' : ''); $tmp['Comment'] = ($cfg['ShowTooltipAliasTB'] ? $tmp['Name'] : $tmp['Comment']); @@ -692,8 +690,7 @@ else if ($num_dbs == 1) { // Displays the list of tables from the current database $tablestack = array(); - for ($j = 0; $j < $num_tables; $j++) { - $table = PMA_mysql_tablename($tables, $j); + while (list($table) = PMA_DBI_fetch_row($tables)) { $alias = (!empty($tooltip_name) && isset($tooltip_name[$table])) ? htmlentities($tooltip_name[$table]) : ''; diff --git a/libraries/auth/config.auth.lib.php b/libraries/auth/config.auth.lib.php index 462356826a..ea1252f5aa 100644 --- a/libraries/auth/config.auth.lib.php +++ b/libraries/auth/config.auth.lib.php @@ -44,7 +44,7 @@ function PMA_auth_check() function PMA_auth_set_user() { return TRUE; -} // end of the 'PMA_auth_set_user()' function +} // end of the 'PMA_auth_set_user()' function /** @@ -69,8 +69,8 @@ function PMA_auth_fails() { global $php_errormsg, $cfg; global $right_font_family, $font_size, $font_bigger; - if (PMA_mysql_error()) { - $conn_error = PMA_mysql_error(); + if (PMA_DBI_getError()) { + $conn_error = PMA_DBI_getError(); } else if (isset($php_errormsg)) { $conn_error = $php_errormsg; } else { diff --git a/libraries/auth/cookie.auth.lib.php b/libraries/auth/cookie.auth.lib.php index 4a12d579be..f0f6f04a14 100644 --- a/libraries/auth/cookie.auth.lib.php +++ b/libraries/auth/cookie.auth.lib.php @@ -591,8 +591,8 @@ global $conn_error; // Deletes password cookie and displays the login form setcookie('pma_cookie_password', base64_encode(''), 0, $GLOBALS['cookie_path'], '' , $GLOBALS['is_https']); - if (PMA_mysql_error()) { - $conn_error = PMA_mysql_error(); + if (PMA_DBI_getError()) { + $conn_error = PMA_DBI_getError(); } else if (isset($php_errormsg)) { $conn_error = $php_errormsg; } else { diff --git a/libraries/bookmark.lib.php b/libraries/bookmark.lib.php index 3a3a9a68e2..d5ee9caa4a 100644 --- a/libraries/bookmark.lib.php +++ b/libraries/bookmark.lib.php @@ -38,29 +38,29 @@ function PMA_getBookmarksParam() /** * Gets the list of bookmarks defined for the current database * - * @param string the current database name - * @param array the bookmark parameters for the current user + * @global resource the controluser db connection handle * - * @return mixed the bookmarks list if defined, false else + * @param string the current database name + * @param array the bookmark parameters for the current user + * + * @return mixed the bookmarks list if defined, false else * * @access public */ function PMA_listBookmarks($db, $cfgBookmark) { + global $dbh; + $query = 'SELECT label, id FROM '. PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table']) . ' WHERE dbase = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND (user = \'' . PMA_sqlAddslashes($cfgBookmark['user']) . '\'' . ' OR user = \'\')'; - if (isset($GLOBALS['dbh'])) { - $result = PMA_mysql_query($query, $GLOBALS['dbh']); - } else { - $result = PMA_mysql_query($query); - } + $result = PMA_DBI_query($query, $dbh); // There is some bookmarks -> store them if ($result > 0 && PMA_DBI_num_rows($result) > 0) { $flag = 1; - while ($row = PMA_mysql_fetch_row($result)) { + while ($row = PMA_DBI_fetch_row($result)) { $bookmark_list[$flag . ' - ' . $row[0]] = $row[1]; $flag++; } // end while @@ -76,17 +76,20 @@ function PMA_listBookmarks($db, $cfgBookmark) /** * Gets the sql command from a bookmark * - * @param string the current database name - * @param array the bookmark parameters for the current user - * @param mixed the id of the bookmark to get - * @param string which field to look up the $id + * @global resource the controluser db connection handle + * + * @param string the current database name + * @param array the bookmark parameters for the current user + * @param mixed the id of the bookmark to get + * @param string which field to look up the $id * - * @return string the sql query + * @return string the sql query * * @access public */ function PMA_queryBookmarks($db, $cfgBookmark, $id, $id_field = 'id') { + global $dbh; if (empty($cfgBookmark['db']) || empty($cfgBookmark['table'])) { return ''; @@ -97,12 +100,8 @@ function PMA_queryBookmarks($db, $cfgBookmark, $id, $id_field = 'id') . ' AND (user = \'' . PMA_sqlAddslashes($cfgBookmark['user']) . '\'' . ' OR user = \'\')' . ' AND ' . PMA_backquote($id_field) . ' = ' . $id; - if (isset($GLOBALS['dbh'])) { - $result = PMA_mysql_query($query, $GLOBALS['dbh']); - } else { - $result = PMA_mysql_query($query); - } - $bookmark_query = @PMA_mysql_result($result, 0, 'query') OR FALSE; + $result = PMA_DBI_try_query($query, $dbh); + list($bookmark_query) = PMA_DBI_fetch_row($result) or array(FALSE); return $bookmark_query; } // end of the 'PMA_queryBookmarks()' function @@ -111,33 +110,23 @@ function PMA_queryBookmarks($db, $cfgBookmark, $id, $id_field = 'id') /** * Adds a bookmark * - * @param array the properties of the bookmark to add - * @param array the bookmark parameters for the current user - * @param boolean whether to make the bookmark available for all users + * @global resource the controluser db connection handle * - * @return boolean whether the INSERT succeeds or not + * @param array the properties of the bookmark to add + * @param array the bookmark parameters for the current user + * @param boolean whether to make the bookmark available for all users + * + * @return boolean whether the INSERT succeeds or not * * @access public */ function PMA_addBookmarks($fields, $cfgBookmark, $all_users = false) { + global $dbh; + $query = 'INSERT INTO ' . PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table']) . ' (id, dbase, user, query, label) VALUES (\'\', \'' . PMA_sqlAddslashes($fields['dbase']) . '\', \'' . ($all_users ? '' : PMA_sqlAddslashes($fields['user'])) . '\', \'' . PMA_sqlAddslashes(urldecode($fields['query'])) . '\', \'' . PMA_sqlAddslashes($fields['label']) . '\')'; - if (isset($GLOBALS['dbh'])) { - $result = PMA_mysql_query($query, $GLOBALS['dbh']); - if (PMA_mysql_error($GLOBALS['dbh'])) { - $error = PMA_mysql_error($GLOBALS['dbh']); - require_once('./header.inc.php'); - PMA_mysqlDie($error); - } - } else { - $result = PMA_mysql_query($query); - if (PMA_mysql_error()) { - $error = PMA_mysql_error(); - require_once('./header.inc.php'); - PMA_mysqlDie($error); - } - } + $result = PMA_DBI_query($query, $dbh); return TRUE; } // end of the 'PMA_addBookmarks()' function @@ -146,6 +135,8 @@ function PMA_addBookmarks($fields, $cfgBookmark, $all_users = false) /** * Deletes a bookmark * + * @global resource the controluser db connection handle + * * @param string the current database name * @param array the bookmark parameters for the current user * @param integer the id of the bookmark to get @@ -154,15 +145,13 @@ function PMA_addBookmarks($fields, $cfgBookmark, $all_users = false) */ function PMA_deleteBookmarks($db, $cfgBookmark, $id) { + global $dbh; + $query = 'DELETE FROM ' . PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table']) . ' WHERE (user = \'' . PMA_sqlAddslashes($cfgBookmark['user']) . '\'' . ' OR user = \'\')' . ' AND id = ' . $id; - if (isset($GLOBALS['dbh'])) { - $result = PMA_mysql_query($query, $GLOBALS['dbh']); - } else { - $result = PMA_mysql_query($query); - } + $result = PMA_DBI_try_query($query, $dbh); } // end of the 'PMA_deleteBookmarks()' function diff --git a/libraries/common.lib.php b/libraries/common.lib.php index 14434bb4f4..65cfad4ae4 100644 --- a/libraries/common.lib.php +++ b/libraries/common.lib.php @@ -458,7 +458,7 @@ if ($is_minimum_common == FALSE) { require_once('./header.inc.php'); if (!$error_message) { - $error_message = PMA_mysql_error(); + $error_message = PMA_DBI_getError(); } if (!$the_query && !empty($GLOBALS['sql_query'])) { $the_query = $GLOBALS['sql_query']; @@ -583,7 +583,7 @@ function PMA_safe_db_list($only_db_check, $dbh, $dblist_cnt, $rs, $userlink, $cf $auth_query = 'SELECT User, Select_priv ' . 'FROM mysql.user ' . 'WHERE User = \'' . PMA_sqlAddslashes($cfg['Server']['user']) . '\''; - $rs = PMA_mysql_query($auth_query, $dbh); // Debug: or PMA_mysqlDie('', $auth_query, FALSE); + $rs = PMA_DBI_try_query($auth_query, $dbh); } // end } @@ -591,7 +591,7 @@ function PMA_safe_db_list($only_db_check, $dbh, $dblist_cnt, $rs, $userlink, $cf // usable db list if (!$dblist_cnt && ($rs && @PMA_DBI_num_rows($rs))) { - $row = PMA_mysql_fetch_array($rs); + $row = PMA_DBI_fetch_assoc($rs); PMA_DBI_free_result($rs); // Correction uva 19991215 // Previous code assumed database "mysql" admin table "db" column @@ -608,7 +608,7 @@ function PMA_safe_db_list($only_db_check, $dbh, $dblist_cnt, $rs, $userlink, $cf // 1. get allowed dbs from the "mysql.db" table // lem9: User can be blank (anonymous user) $local_query = 'SELECT DISTINCT Db FROM mysql.db WHERE Select_priv = \'Y\' AND (User = \'' . PMA_sqlAddslashes($cfg['Server']['user']) . '\' OR User = \'\')'; - $rs = PMA_mysql_query($local_query, $dbh); // Debug: or PMA_mysqlDie('', $local_query, FALSE); + $rs = PMA_DBI_try_query($local_query, $dbh); if ($rs && @PMA_DBI_num_rows($rs)) { // Will use as associative array of the following 2 code // lines: @@ -620,7 +620,7 @@ function PMA_safe_db_list($only_db_check, $dbh, $dblist_cnt, $rs, $userlink, $cf // populating $dblist[], as previous code did. But it is // now populated with actual database names instead of // with regular expressions. - while ($row = PMA_mysql_fetch_array($rs)) { + while ($row = PMA_DBI_fetch_assoc($rs)) { // loic1: all databases cases - part 1 if (empty($row['Db']) || $row['Db'] == '%') { $uva_mydbs['%'] = 1; @@ -632,15 +632,15 @@ function PMA_safe_db_list($only_db_check, $dbh, $dblist_cnt, $rs, $userlink, $cf } } // end while PMA_DBI_free_result($rs); - $uva_alldbs = mysql_list_dbs($GLOBALS['dbh']); + $uva_alldbs = PMA_DBI_query('SHOW DATABASES;', $GLOBALS['dbh']); // loic1: all databases cases - part 2 if (isset($uva_mydbs['%'])) { - while ($uva_row = PMA_mysql_fetch_array($uva_alldbs)) { + while ($uva_row = PMA_DBI_fetch_row($uva_alldbs)) { $dblist[] = $uva_row[0]; } // end while } // end if else { - while ($uva_row = PMA_mysql_fetch_array($uva_alldbs)) { + while ($uva_row = PMA_DBI_fetch_row($uva_alldbs)) { $uva_db = $uva_row[0]; if (isset($uva_mydbs[$uva_db]) && $uva_mydbs[$uva_db] == 1) { $dblist[] = $uva_db; @@ -668,9 +668,9 @@ function PMA_safe_db_list($only_db_check, $dbh, $dblist_cnt, $rs, $userlink, $cf // 2. get allowed dbs from the "mysql.tables_priv" table $local_query = 'SELECT DISTINCT Db FROM mysql.tables_priv WHERE Table_priv LIKE \'%Select%\' AND User = \'' . PMA_sqlAddslashes($cfg['Server']['user']) . '\''; - $rs = PMA_mysql_query($local_query, $dbh); // Debug: or PMA_mysqlDie('', $local_query, FALSE); + $rs = PMA_DBI_try_query($local_query, $dbh); if ($rs && @PMA_DBI_num_rows($rs)) { - while ($row = PMA_mysql_fetch_array($rs)) { + while ($row = PMA_DBI_fetch_assoc($rs)) { if (PMA_isInto($row['Db'], $dblist) == -1) { $dblist[] = $row['Db']; } @@ -996,7 +996,7 @@ if ($is_minimum_common == FALSE) { // Connects to the server (validates user's login) $userlink = PMA_DBI_connect($cfg['Server']['user'], $cfg['Server']['password']); - + if (empty($dbh)) { $dbh = $userlink; } @@ -1044,18 +1044,18 @@ if ($is_minimum_common == FALSE) { } if ($is_show_dbs && ereg('(^|[^\])(_|%)', $dblist[$i])) { $local_query = 'SHOW DATABASES LIKE \'' . $dblist[$i] . '\''; - $rs = PMA_mysql_query($local_query, $dbh); + $rs = PMA_DBI_query($local_query, $dbh); // "SHOW DATABASES" statement is disabled if ($i == 0 - && (PMA_mysql_error() && mysql_errno() == 1045)) { + && (substr(PMA_DBI_getError($dbh), 1, 4) == 1045)) { $true_dblist[] = str_replace('\\_', '_', str_replace('\\%', '%', $dblist[$i])); $is_show_dbs = FALSE; } // Debug - // else if (PMA_mysql_error()) { - // PMA_mysqlDie('', $local_query, FALSE); + // else if (PMA_DBI_getError($dbh)) { + // PMA_mysqlDie(PMA_DBI_getError($dbh), $local_query, FALSE); // } - while ($row = @PMA_mysql_fetch_row($rs)) { + while ($row = @PMA_DBI_fetch_row($rs)) { $true_dblist[] = $row[0]; } // end while if ($rs) { @@ -1110,7 +1110,7 @@ if ($is_minimum_common == FALSE) { if ($num_dbs) { $true_dblist = array(); for ($i = 0; $i < $num_dbs; $i++) { - $dblink = @PMA_mysql_select_db($dblist[$i]); + $dblink = @PMA_DBI_select_db($dblist[$i]); if ($dblink) { $true_dblist[] = $dblist[$i]; } // end if @@ -1245,9 +1245,8 @@ if ($is_minimum_common == FALSE) { function PMA_countRecords($db, $table, $ret = FALSE) { global $err_url, $cfg; - $local_query = 'SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\''; - $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url); - $showtable = PMA_mysql_fetch_array($result); + $result = PMA_DBI_query('SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\';'); + $showtable = PMA_DBI_fetch_assoc($result); $num = (isset($showtable['Rows']) ? $showtable['Rows'] : 0); if ($num < $cfg['MaxExactCount']) { unset($num); @@ -1255,8 +1254,8 @@ if ($is_minimum_common == FALSE) { PMA_DBI_free_result($result); if (!isset($num)) { - $result = PMA_mysql_query('SELECT COUNT(*) AS num FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table)) or PMA_mysqlDie('', $local_query, '', $err_url); - $num = ($result) ? PMA_mysql_result($result, 0, 'num') : 0; + $result = PMA_DBI_query('SELECT COUNT(*) AS num FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table)); + list($num) = ($result) ? PMA_DBI_fetch_row($result) : array(0); PMA_DBI_free_result($result); } if ($ret) { @@ -1302,9 +1301,9 @@ if (typeof(window.parent) != 'undefined' // Corrects the tooltip text via JS if required else if (!empty($GLOBALS['table']) && $cfg['ShowTooltip']) { - $result = @PMA_mysql_query('SHOW TABLE STATUS FROM ' . PMA_backquote($GLOBALS['db']) . ' LIKE \'' . PMA_sqlAddslashes($GLOBALS['table'], TRUE) . '\''); + $result = PMA_DBI_try_query('SHOW TABLE STATUS FROM ' . PMA_backquote($GLOBALS['db']) . ' LIKE \'' . PMA_sqlAddslashes($GLOBALS['table'], TRUE) . '\''); if ($result) { - $tbl_status = PMA_mysql_fetch_array($result, MYSQL_ASSOC); + $tbl_status = PMA_DBI_fetch_assoc($result); $tooltip = (empty($tbl_status['Comment'])) ? '' : $tbl_status['Comment'] . ' '; @@ -1333,14 +1332,14 @@ if (typeof(document.getElementById) != 'undefined' if (isset($GLOBALS['table']) && isset($GLOBALS['sql_query']) && $GLOBALS['sql_query'] == 'TRUNCATE TABLE ' . PMA_backquote($GLOBALS['table'])) { if (!isset($tbl_status)) { - $result = @PMA_mysql_query('SHOW TABLE STATUS FROM ' . PMA_backquote($GLOBALS['db']) . ' LIKE \'' . PMA_sqlAddslashes($GLOBALS['table'], TRUE) . '\''); + $result = @PMA_DBI_try_query('SHOW TABLE STATUS FROM ' . PMA_backquote($GLOBALS['db']) . ' LIKE \'' . PMA_sqlAddslashes($GLOBALS['table'], TRUE) . '\''); if ($result) { - $tbl_status = PMA_mysql_fetch_array($result, MYSQL_ASSOC); + $tbl_status = PMA_DBI_fetch_assoc($result); PMA_DBI_free_result($result); } } if (isset($tbl_status) && (int) $tbl_status['Index_length'] > 1024) { - @PMA_mysql_query('REPAIR TABLE ' . PMA_backquote($GLOBALS['table'])); + PMA_DBI_try_query('REPAIR TABLE ' . PMA_backquote($GLOBALS['table'])); } } unset($tbl_status); diff --git a/libraries/database_interface.lib.php b/libraries/database_interface.lib.php index 1830397992..35dc18317c 100644 --- a/libraries/database_interface.lib.php +++ b/libraries/database_interface.lib.php @@ -15,4 +15,61 @@ function PMA_DBI_query($query, $dbh = '') { return $res; } +function PMA_DBI_get_dblist($link = NULL) { + if (empty($link)) { + if (isset($GLOBALS['userlink'])) { + $link = $GLOBALS['userlink']; + } else { + return FALSE; + } + } + $res = PMA_DBI_try_query('SHOW DATABASES;', $link); + $dbs_array = array(); + while ($row = PMA_DBI_fetch_row($res)) { + + // Before MySQL 4.0.2, SHOW DATABASES could send the + // whole list, so check if we really have access: + if (PMA_MYSQL_CLIENT_API < 40002) { + $dblink = @PMA_DBI_select_db($row[0], $link); + if (!$dblink) { + continue; + } + } + $dbs_array[] = $row[0]; + } + PMA_DBI_free_result($res); + unset($res); + + return $dbs_array; +} + +function PMA_DBI_get_tables($database, $link = NULL) { + $result = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($database) . ';'); + $tables = array(); + while (list($current) = PMA_DBI_fetch_row($result)) { + $tables[] = $current; + } + PMA_DBI_free_result($result); + + return $tables; +} + +function PMA_DBI_get_fields($database, $table, $link = NULL) { + if (empty($link)) { + if (isset($GLOBALS['userlink'])) { + $link = $GLOBALS['userlink']; + } else { + return FALSE; + } + } + $result = PMA_DBI_query('SHOW FULL FIELDS FROM ' . PMA_backquote($database) . '.' . PMA_backquote($table), $link); + + $fields = array(); + while ($row = PMA_DBI_fetch_assoc($result)) { + $fields[] = $row; + } + + return $fields; +} + ?>
\ No newline at end of file diff --git a/libraries/db_table_exists.lib.php b/libraries/db_table_exists.lib.php index 3580af1dad..751805e856 100644 --- a/libraries/db_table_exists.lib.php +++ b/libraries/db_table_exists.lib.php @@ -10,7 +10,7 @@ if (!isset($is_db) || !$is_db) { // Not a valid db name -> back to the welcome page if (!empty($db)) { - $is_db = @PMA_mysql_select_db($db); + $is_db = @PMA_DBI_select_db($db); } if (empty($db) || !$is_db) { if (!isset($is_transformation_wrapper)) { @@ -22,7 +22,7 @@ if (!isset($is_db) || !$is_db) { if (!isset($is_table) || !$is_table) { // Not a valid table name -> back to the db_details.php if (!empty($table)) { - $is_table = @PMA_mysql_query('SHOW TABLES LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\''); + $is_table = PMA_DBI_try_query('SHOW TABLES LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\';'); } if (empty($table) || !($is_table && @PMA_DBI_num_rows($is_table))) { diff --git a/libraries/dbi/mysql.dbi.lib.php b/libraries/dbi/mysql.dbi.lib.php index bfdfb69148..063ee5657c 100644 --- a/libraries/dbi/mysql.dbi.lib.php +++ b/libraries/dbi/mysql.dbi.lib.php @@ -6,8 +6,6 @@ * Interface to the classic MySQL extension */ -require_once('./libraries/charset_conversion.lib.php'); - /** * Loads the mysql extensions if it is not loaded yet */ @@ -36,6 +34,7 @@ function PMA_DBI_connect($user, $password) { $server_port = (empty($cfg['Server']['port'])) ? '' : ':' . $cfg['Server']['port']; + if (strtolower($cfg['Server']['connect_type']) == 'tcp') { $cfg['Server']['socket'] = ''; } @@ -64,10 +63,10 @@ function PMA_DBI_connect($user, $password) { } // end if if (!defined('PMA_MYSQL_INT_VERSION')) { - $result = PMA_DBI_try_query('SELECT VERSION() AS version', $link); + $result = mysql_query('SELECT VERSION() AS version', $link); if ($result != FALSE && @mysql_num_rows($result) > 0) { - $row = PMA_DBI_fetch_assoc($result); - $match = explode('.', $row['version']); + $row = mysql_fetch_row($result); + $match = explode('.', $row[0]); mysql_free_result($result); } if (!isset($row)) { @@ -75,14 +74,35 @@ function PMA_DBI_connect($user, $password) { define('PMA_MYSQL_STR_VERSION', '3.23.32'); } else{ define('PMA_MYSQL_INT_VERSION', (int)sprintf('%d%02d%02d', $match[0], $match[1], intval($match[2]))); - define('PMA_MYSQL_STR_VERSION', $row['version']); + define('PMA_MYSQL_STR_VERSION', $row[0]); unset($result, $row, $match); } } + if (PMA_MYSQL_INT_VERSION >= 40100) { + mysql_query('SET CHARACTER SET utf8;', $link); + mysql_query('SET SESSION character_set_connection = \'utf8\';', $link); + } else { + require_once('./libraries/charset_conversion.lib.php'); + } + return $link; } +function PMA_DBI_select_db($dbname, $link = '') { + if (empty($link)) { + if (isset($GLOBALS['userlink'])) { + $link = $GLOBALS['userlink']; + } else { + return FALSE; + } + } + if (PMA_MYSQL_INT_VERSION < 40100) { + $dbname = PMA_convert_charset($dbname); + } + return mysql_select_db($dbname, $link); +} + function PMA_DBI_try_query($query, $link = '') { if (empty($link)) { if (isset($GLOBALS['userlink'])) { @@ -91,6 +111,9 @@ function PMA_DBI_try_query($query, $link = '') { return FALSE; } } + if (PMA_MYSQL_INT_VERSION < 40100) { + $query = PMA_convert_charset($query); + } return mysql_query(PMA_convert_charset($query), $link); } @@ -104,7 +127,8 @@ function PMA_mysql_fetch_array($result, $type = FALSE) { } else { $data = mysql_fetch_array($result); } - if (!(isset($cfg['AllowAnywhereRecoding']) && $cfg['AllowAnywhereRecoding'] && $allow_recoding)) { + if (PMA_MYSQL_INT_VERSION >= 40100 + || !(isset($cfg['AllowAnywhereRecoding']) && $cfg['AllowAnywhereRecoding'] && $allow_recoding)) { /* No recoding -> return data as we got them */ return $data; } else { @@ -142,7 +166,7 @@ function PMA_DBI_fetch_row($result) { } function PMA_DBI_free_result($result) { - return mysql_free_result($result); + return @mysql_free_result($result); } function PMA_DBI_getError($link = '') { @@ -154,48 +178,23 @@ function PMA_DBI_getError($link = '') { } } $error = mysql_errno($link); - if ($error) { - $error = mysql_errno($link); - if (!empty($error)) { - $error = '#' . ((string) $error) . ' - ' . PMA_convert_display_charset(mysql_error($link)); - } + if ($error && PMA_MYSQL_INT_VERSION >= 40100) { + $error = '#' . ((string) $error) . ' - ' . mysql_error($link); + } elseif ($error) { + $error = '#' . ((string) $error) . ' - ' . PMA_convert_display_charset(mysql_error($link)); } + return $error; } function PMA_DBI_close($link = '') { if (empty($link)) { - $link = $GLOBALS['userlink']; - } - @mysql_close($link); -} - -function PMA_DBI_get_dblist($link = '') { - if (empty($link)) { if (isset($GLOBALS['userlink'])) { $link = $GLOBALS['userlink']; } else { return FALSE; } } - $res = PMA_DBI_try_query('SHOW DATABASES;', $link); - $dbs_array = array(); - while ($row = PMA_DBI_fetch_row($res)) { - // not sure if we have to convert before the (possible) select_db() - $dbname = PMA_convert_display_charset($row[0]); - - // Before MySQL 4.0.2, SHOW DATABASES could send the - // whole list, so check if we really have access: - if (PMA_MYSQL_CLIENT_API < 40002) { - $dblink = @PMA_mysql_select_db($dbname); - if (!dblink) { - continue; - } - } - $dbs_array[] = $dbname; - } - PMA_DBI_free_result($res); - unset($res); - return $dbs_array; + return @mysql_close($link); } function PMA_DBI_num_rows($result) { @@ -224,4 +223,13 @@ function PMA_DBI_affected_rows($link) { return mysql_affected_rows($link); } -?> +function PMA_DBI_get_fields_meta($result) { + $fields = array(); + $num_fields = mysql_num_fields($result); + for ($i = 0; $i < $num_fields; $i++) { + $fields[] = mysql_fetch_field($result, $i); + } + return $fields; +} + +?>
\ No newline at end of file diff --git a/libraries/dbi/mysqli.dbi.lib.php b/libraries/dbi/mysqli.dbi.lib.php new file mode 100644 index 0000000000..9d487eef1d --- /dev/null +++ b/libraries/dbi/mysqli.dbi.lib.php @@ -0,0 +1,216 @@ +<?php +/* $Id$ */ +// vim: expandtab sw=4 ts=4 sts=4: + +/** + * Interface to the improved MySQL extension (MySQLi) + */ + +/** + * Loads the MySQLi extension if it is not loaded yet + */ +if (!@function_exists('mysqli_connect')) { + PMA_dl('mysqli'); +} + +// check whether mysql is available +if (!@function_exists('mysqli_connect')) { + require_once('./libraries/header_http.inc.php'); + echo $strCantLoadMySQL . '<br />' . "\n" // TODO: Replace by a MySQLi related message + . '<a href="./Documentation.html#faqmysql" target="documentation">' . $GLOBALS['strDocu'] . '</a>' . "\n"; + exit; +} + +// MySQL client API +if (!defined('PMA_MYSQL_CLIENT_API')) { + $client_api = explode('.', mysqli_get_client_info()); + define('PMA_MYSQL_CLIENT_API', (int)sprintf('%d%02d%02d', $client_api[0], $client_api[1], intval($client_api[2]))); + unset($client_api); +} + +function PMA_DBI_connect($user, $password) { + global $cfg, $php_errormsg; + + $server_port = (empty($cfg['Server']['port'])) + ? FALSE + : (int) $cfg['Server']['port']; + + if (strtolower($cfg['Server']['connect_type']) == 'tcp') { + $cfg['Server']['socket'] = ''; + } + + $server_socket = (empty($cfg['Server']['socket'])) + ? FALSE + : $cfg['Server']['socket']; + + $link = mysqli_connect($cfg['Server']['host'], $user, $password, FALSE, $server_port, $server_socket); + + if (empty($link)) { + PMA_auth_fails(); + } // end if + + if (!defined('PMA_MYSQL_INT_VERSION')) { + $result = mysqli_query($link, 'SELECT VERSION() AS version;', MYSQLI_STORE_RESULT); + if ($result != FALSE && @mysqli_num_rows($result) > 0) { + $row = mysqli_fetch_row($result); + $match = explode('.', $row[0]); + mysqli_free_result($result); + } + if (!isset($row)) { + define('PMA_MYSQL_INT_VERSION', 32332); + define('PMA_MYSQL_STR_VERSION', '3.23.32'); + } else{ + define('PMA_MYSQL_INT_VERSION', (int)sprintf('%d%02d%02d', $match[0], $match[1], intval($match[2]))); + define('PMA_MYSQL_STR_VERSION', $row[0]); + unset($result, $row, $match); + } + } + + if (PMA_MYSQL_INT_VERSION >= 40100) { + mysqli_query($link, 'SET CHARACTER SET utf8;', MYSQLI_STORE_RESULT); + mysqli_query($link, 'SET SESSION character_set_connection = \'utf8\';', MYSQLI_STORE_RESULT); + } else { + require_once('./libraries/charset_conversion.lib.php'); + } + + return $link; +} + +function PMA_DBI_select_db($dbname, $link = '') { + if (empty($link)) { + if (isset($GLOBALS['userlink'])) { + $link = $GLOBALS['userlink']; + } else { + return FALSE; + } + } + if (PMA_MYSQL_INT_VERSION < 40100) { + $dbname = PMA_convert_charset($dbname); + } + return mysqli_select_db($link, $dbname); +} + +function PMA_DBI_try_query($query, $link = '') { + if (empty($link)) { + if (isset($GLOBALS['userlink'])) { + $link = $GLOBALS['userlink']; + } else { + return FALSE; + } + } + if (PMA_MYSQL_INT_VERSION < 40100) { + $query = PMA_convert_charset($query); + } + return mysqli_query($link, $query, MYSQLI_USE_RESULT); +} + +// The following function is meant for internal use only. +// Do not call it from outside this library! +function PMA_mysqli_fetch_array($result, $type = FALSE) { + global $cfg, $allow_recoding, $charset, $convcharset; + + if ($type != FALSE) { + $data = mysqli_fetch_array($result, $type); + } else { + $data = mysqli_fetch_array($result); + } + if (PMA_MYSQL_INT_VERSION >= 40100 + || !(isset($cfg['AllowAnywhereRecoding']) && $cfg['AllowAnywhereRecoding'] && $allow_recoding)) { + /* No recoding -> return data as we got them */ + return $data; + } else { + $ret = array(); + $num = mysqli_num_fields($result); + $fields = mysqli_fetch_fields($result); + $i = 0; + for($i = 0; $i < $num; $i++) { + if (!$meta) { + /* No meta information available -> we guess that it should be converted */ + if (isset($data[$i])) $ret[$i] = PMA_convert_display_charset($data[$i]); + if (isset($data[$name])) $ret[PMA_convert_display_charset($name)] = PMA_convert_display_charset($data[$name]); + } else { + /* Meta information available -> check type of field and convert it according to the type */ + if (stristr($fields[$i]->type, 'BLOB') || stristr($fields[$i]->type, 'BINARY')) { + if (isset($data[$i])) $ret[$i] = $data[$i]; + if (isset($data[$fields[$i]->name])) $ret[PMA_convert_display_charset($fields[$i]->name)] = $data[$fields[$i]->name]; + } else { + if (isset($data[$i])) $ret[$i] = PMA_convert_display_charset($data[$i]); + if (isset($data[$fields[$i]->name])) $ret[PMA_convert_display_charset($fields[$i]->name)] = PMA_convert_display_charset($data[$fields[$i]->name]); + } + } + } + return $ret; + } +} + +function PMA_DBI_fetch_assoc($result) { + return PMA_mysqli_fetch_array($result, MYSQLI_ASSOC); +} + +function PMA_DBI_fetch_row($result) { + return PMA_mysqli_fetch_array($result, MYSQLI_NUM); +} + +function PMA_DBI_free_result($result) { + return @mysqli_free_result($result); +} + +function PMA_DBI_getError($link = '') { + if (empty($link)) { + if (isset($GLOBALS['userlink'])) { + $link = $GLOBALS['userlink']; + } else { + return FALSE; + } + } + $error = mysqli_errno($link); + if ($error && PMA_MYSQL_INT_VERSION >= 40100) { + $error = '#' . ((string) $error) . ' - ' . mysqli_error($link); + } elseif ($error) { + $error = '#' . ((string) $error) . ' - ' . PMA_convert_display_charset(mysqli_error($link)); + } + return $error; +} + +function PMA_DBI_close($link = '') { + if (empty($link)) { + if (isset($GLOBALS['userlink'])) { + $link = $GLOBALS['userlink']; + } else { + return FALSE; + } + } + return @mysqli_close($link); +} + +function PMA_DBI_num_rows($result) { + return @mysqli_num_rows($result); +} + +function PMA_DBI_insert_id($link) { + if (empty($link)) { + if (isset($GLOBALS['userlink'])) { + $link = $GLOBALS['userlink']; + } else { + return FALSE; + } + } + return mysqli_insert_id($link); +} + +function PMA_DBI_affected_rows($link) { + if (empty($link)) { + if (isset($GLOBALS['userlink'])) { + $link = $GLOBALS['userlink']; + } else { + return FALSE; + } + } + return mysqli_affected_rows($link); +} + +function PMA_DBI_get_fields_meta($result) { + return mysqli_fetch_fields($result); +} + +?>
\ No newline at end of file diff --git a/libraries/display_tbl.lib.php b/libraries/display_tbl.lib.php index dee4a4f18d..068e6e1a45 100644 --- a/libraries/display_tbl.lib.php +++ b/libraries/display_tbl.lib.php @@ -485,13 +485,12 @@ function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $ isset($analyzed_sql[0]['table_ref']) && count($analyzed_sql[0]['table_ref']) == 1) { // grab indexes data: - $local_query = 'SHOW KEYS FROM ' . PMA_backquote($table); - $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url_0); - $idx_cnt = PMA_DBI_num_rows($result); + $result = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';'); + $idx_cnt = PMA_DBI_num_rows($result); $prev_index = ''; for ($i = 0; $i < $idx_cnt; $i++) { - $row = (defined('PMA_IDX_INCLUDED') ? $ret_keys[$i] : PMA_mysql_fetch_array($result)); + $row = (defined('PMA_IDX_INCLUDED') ? $ret_keys[$i] : PMA_DBI_fetch_assoc($result)); if ($row['Key_name'] != $prev_index ){ $indexes[] = $row['Key_name']; @@ -749,7 +748,7 @@ function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $ // FROM `PMA_relation` AS `1` , `PMA_relation` AS `2` if (($is_join - && !preg_match('~([^[:space:],]|`[^`]`)[[:space:]]+(as[[:space:]]+)?' . $fields_meta[$i]->name . '~i', $select_stt[1], $parts)) + && !preg_match('~([^[:space:],]|`[^`]`)[[:space:]]+(as[[:space:]]+)?' . $fields_meta[$i]->name . '~i', $select_stt[1], $parts)) || ( isset($analyzed_sql[0]['select_expr'][$i]['expr']) && isset($analyzed_sql[0]['select_expr'][$i]['column']) && $analyzed_sql[0]['select_expr'][$i]['expr'] != @@ -974,7 +973,10 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) // loic1: use 'PMA_mysql_fetch_array' rather than 'PMA_mysql_fetch_row' // to get the NULL values - while ($row = PMA_mysql_fetch_array($dt_result)) { + // rabus: This function needs a little rework. + // Using MYSQL_BOTH just pollutes the memory! + + while ($row = PMA_mysql_fetch_array($dt_result)) { // !UNWRAPPED FUNCTION! // lem9: "vertical display" mode stuff if (($row_no != 0) && ($repeat_cells != 0) && !($row_no % $repeat_cells) && ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped')) { @@ -1029,7 +1031,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); + $field_flags = PMA_mysql_field_flags($dt_result, $i); // !UNWRAPPED FUNCTION! $meta = $fields_meta[$i]; // do not use an alias in a condition @@ -1300,9 +1302,9 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) . ' FROM ' . PMA_backquote($map[$meta->name][3]) . '.' . PMA_backquote($map[$meta->name][0]) . ' WHERE ' . PMA_backquote($map[$meta->name][1]) . ' = ' . $row[$pointer]; - $dispresult = PMA_mysql_query($dispsql); + $dispresult = PMA_DBI_try_query($dispsql); if ($dispresult && PMA_DBI_num_rows($dispresult) > 0) { - $dispval = PMA_mysql_result($dispresult, 0); + list($dispval) = PMA_DBI_fetch_row($dispresult, 0); } else { $dispval = $GLOBALS['strLinkNotFound']; @@ -1338,7 +1340,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); + $field_flags = PMA_mysql_field_flags($dt_result, $i); // !UNWRAPPED FUNCTION! if (stristr($field_flags, 'BINARY')) { $blobtext = '[BLOB'; if (isset($row[$pointer])) { @@ -1385,7 +1387,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); + $field_flags = PMA_mysql_field_flags($dt_result, $i); // !UNWRAPPED FUNCTION! if (stristr($field_flags, 'BINARY')) { $row[$pointer] = str_replace("\x00", '\0', $row[$pointer]); $row[$pointer] = str_replace("\x08", '\b', $row[$pointer]); @@ -1427,9 +1429,9 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) . ' FROM ' . PMA_backquote($map[$meta->name][3]) . '.' . PMA_backquote($map[$meta->name][0]) . ' WHERE ' . PMA_backquote($map[$meta->name][1]) . ' = \'' . PMA_sqlAddslashes($row[$pointer]) . '\''; - $dispresult = @PMA_mysql_query($dispsql); + $dispresult = PMA_DBI_try_query($dispsql); if ($dispresult && PMA_DBI_num_rows($dispresult) > 0) { - $dispval = PMA_mysql_result($dispresult, 0); + list($dispval) = PMA_DBI_fetch_row($dispresult); } else { $dispval = $GLOBALS['strLinkNotFound']; diff --git a/libraries/export/csv.php b/libraries/export/csv.php index 5a56cb7d9e..a8f47d00c4 100644 --- a/libraries/export/csv.php +++ b/libraries/export/csv.php @@ -113,18 +113,18 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { global $escaped; // Gets the data from the database - $result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', $sql_query, '', $error_url); - $fields_cnt = mysql_num_fields($result); + $result = PMA_DBI_query($sql_query); + $fields_cnt = PMA_DBI_num_fields($result); // If required, get fields name at the first line if (isset($GLOBALS['showcsvnames']) && $GLOBALS['showcsvnames'] == 'yes') { $schema_insert = ''; for ($i = 0; $i < $fields_cnt; $i++) { if ($enclosed == '') { - $schema_insert .= stripslashes(mysql_field_name($result, $i)); + $schema_insert .= stripslashes(mysql_field_name($result, $i)); //! UNWRAPPED FUNCTION! } else { $schema_insert .= $enclosed - . str_replace($enclosed, $escaped . $enclosed, stripslashes(mysql_field_name($result, $i))) + . str_replace($enclosed, $escaped . $enclosed, stripslashes(mysql_field_name($result, $i))) //! UNWRAPPED FUNCTION! . $enclosed; } $schema_insert .= $separator; @@ -134,7 +134,7 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { } // end if // Format the data - while ($row = PMA_mysql_fetch_row($result)) { + while ($row = PMA_DBI_fetch_row($result)) { $schema_insert = ''; for ($j = 0; $j < $fields_cnt; $j++) { if (!isset($row[$j])) { diff --git a/libraries/export/latex.php b/libraries/export/latex.php index 57c24fe155..3df88f2fbc 100644 --- a/libraries/export/latex.php +++ b/libraries/export/latex.php @@ -159,7 +159,7 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { } // print the whole table - while ($record = PMA_mysql_fetch_array($result, MYSQL_ASSOC)) { + while ($record = PMA_DBI_fetch_assoc($result)) { $buffer = ''; // print each row @@ -212,9 +212,9 @@ function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = fals /** * Gets fields properties */ - PMA_mysql_select_db($db); + PMA_DBI_select_db($db); $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table); - $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $error_url); + $result = PMA_DBI_query($local_query); $fields_cnt = PMA_DBI_num_rows($result); // Check if we can use Relations (Mike Beck) @@ -237,9 +237,9 @@ function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = fals * Get the unique keys in the table */ $keys_query = 'SHOW KEYS FROM ' . PMA_backquote($table) . ' FROM '. PMA_backquote($db); - $keys_result = PMA_mysql_query($keys_query) or PMA_mysqlDie('', $keys_query, '', $error_url); + $keys_result = PMA_DBI_query($keys_query); $unique_keys = array(); - while($key = PMA_mysql_fetch_array($keys_result)) { + while($key = PMA_DBI_fetch_assoc($keys_result)) { if ($key['Non_unique'] == 0) $unique_keys[] = $key['Column_name']; } @@ -298,7 +298,7 @@ function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = fals if (!PMA_exportOutputHandler($buffer)) return FALSE; - while ($row = PMA_mysql_fetch_array($result)) { + while ($row = PMA_DBI_fetch_assoc($result)) { $type = $row['Type']; // reformat mysql query output - staybyte - 9. June 2001 diff --git a/libraries/export/sql.php b/libraries/export/sql.php index e1a062ca29..ce6098977f 100644 --- a/libraries/export/sql.php +++ b/libraries/export/sql.php @@ -21,9 +21,9 @@ error_reporting(E_ALL); * even for 'text' fields. */ function PMA_fieldTypes($db, $table,$use_backquotes) { - PMA_mysql_select_db($db); - $table_def = PMA_mysql_query('SHOW FIELDS FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table)); - while($row = @PMA_mysql_fetch_array($table_def)) { + PMA_DBI_select_db($db); + $table_def = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table)); + while($row = PMA_DBI_fetch_assoc($table_def)) { $types[PMA_backquote($row['Field'],$use_backquotes)] = ereg_replace('\\(.*', '', $row['Type']); } return $types; @@ -154,10 +154,10 @@ function PMA_getTableDef($db, $table, $crlf, $error_url, $show_dates = false) $new_crlf = $crlf; - $result = PMA_mysql_query('SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \'' . PMA_sqlAddslashes($table) . '\''); + $result = PMA_DBI_query('SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \'' . PMA_sqlAddslashes($table) . '\''); if ($result != FALSE) { if (PMA_DBI_num_rows($result) > 0) { - $tmpres = PMA_mysql_fetch_array($result); + $tmpres = PMA_DBI_fetch_assoc($result); if (isset($GLOBALS['auto_increment']) && !empty($tmpres['Auto_increment'])) { $auto_increment .= ' AUTO_INCREMENT=' . $tmpres['Auto_increment'] . ' '; } @@ -189,13 +189,13 @@ function PMA_getTableDef($db, $table, $crlf, $error_url, $show_dates = false) // Steve Alberty's patch for complete table dump, // Whether to quote table and fields names or not if ($use_backquotes) { - PMA_mysql_query('SET SQL_QUOTE_SHOW_CREATE = 1'); + PMA_DBI_query('SET SQL_QUOTE_SHOW_CREATE = 1'); } else { - PMA_mysql_query('SET SQL_QUOTE_SHOW_CREATE = 0'); + PMA_DBI_query('SET SQL_QUOTE_SHOW_CREATE = 0'); } - $result = PMA_mysql_query('SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table)); + $result = PMA_DBI_query('SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table)); if ($result != FALSE && PMA_DBI_num_rows($result) > 0) { - $tmpres = PMA_mysql_fetch_array($result); + $tmpres = PMA_DBI_fetch_row($result); // Fix for case problems with winwin, thanks to // Pawe³ Szczepañski <pauluz at users.sourceforge.net> $pos = strpos($tmpres[1], ' ('); @@ -395,9 +395,9 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) $buffer = ''; - $result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', $sql_query, '', $error_url); + $result = PMA_DBI_query($sql_query); if ($result != FALSE) { - $fields_cnt = mysql_num_fields($result); + $fields_cnt = PMA_DBI_num_fields($result); $rows_cnt = PMA_DBI_num_rows($result); // get the real types of the table's fields (in an array) @@ -415,7 +415,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); + $field_set[$j] = PMA_backquote(PMA_mysql_field_name($result, $j), $use_backquotes); //! UNWRAPPED FUNCTION! } $type = $field_types[$field_set[$j]]; @@ -468,7 +468,7 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) $replace = array('\0', '\n', '\r', '\Z'); $current_row = 0; - while ($row = PMA_mysql_fetch_row($result)) { + while ($row = PMA_DBI_fetch_row($result)) { $current_row++; for ($j = 0; $j < $fields_cnt; $j++) { if (!isset($row[$j])) { diff --git a/libraries/export/xml.php b/libraries/export/xml.php index c2b0592e3d..aafedf506f 100644 --- a/libraries/export/xml.php +++ b/libraries/export/xml.php @@ -27,7 +27,7 @@ function PMA_exportComment($text) { function PMA_exportHeader() { global $crlf; global $cfg; - + if ($GLOBALS['output_charset_conversion']) { $charset = $GLOBALS['charset_of_file']; } else { @@ -113,18 +113,18 @@ function PMA_exportDBCreate($db) { * @access public */ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { - $result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', $sql_query, '', $error_url); - - $columns_cnt = mysql_num_fields($result); + $result = PMA_DBI_query($sql_query); + + $columns_cnt = PMA_DBI_num_fields($result); for ($i = 0; $i < $columns_cnt; $i++) { - $columns[$i] = stripslashes(mysql_field_name($result, $i)); + $columns[$i] = stripslashes(mysql_field_name($result, $i)); //! UNWRAPPED FUNCTION! } unset($i); - + $buffer = ' <!-- ' . $GLOBALS['strTable'] . ' ' . $table . ' -->' . $crlf; if (!PMA_exportOutputHandler($buffer)) return FALSE; - - while ($record = PMA_mysql_fetch_array($result, MYSQL_ASSOC)) { + + while ($record = PMA_DBI_fetch_assoc($result)) { $buffer = ' <' . $table . '>' . $crlf; for ($i = 0; $i < $columns_cnt; $i++) { // There is no way to dectect a "NULL" value with PHP3 @@ -134,7 +134,7 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { } } $buffer .= ' </' . $table . '>' . $crlf; - + if (!PMA_exportOutputHandler($buffer)) return FALSE; } PMA_DBI_free_result($result); diff --git a/libraries/get_foreign.lib.php b/libraries/get_foreign.lib.php index b29f48f4bc..35957cf084 100644 --- a/libraries/get_foreign.lib.php +++ b/libraries/get_foreign.lib.php @@ -36,7 +36,7 @@ if ($foreigners && isset($foreigners[$field])) { . ' FROM ' . PMA_backquote($foreign_db) . '.' . PMA_backquote($foreign_table) . (($foreign_display == FALSE) ? '' :' ORDER BY ' . PMA_backquote($foreign_table) . '.' . PMA_backquote($foreign_display)) . (isset($foreign_limit) ? $foreign_limit : ''); - $disp = PMA_mysql_query($dispsql); + $disp = PMA_DBI_query($dispsql); } else { unset($disp); diff --git a/libraries/mysql_charsets.lib.php b/libraries/mysql_charsets.lib.php index ae4d016e3b..841fd2093b 100644 --- a/libraries/mysql_charsets.lib.php +++ b/libraries/mysql_charsets.lib.php @@ -4,11 +4,10 @@ if (PMA_MYSQL_INT_VERSION >= 40100){ - $res = PMA_mysql_query('SHOW CHARACTER SET;', $userlink) - or PMA_mysqlDie(PMA_mysql_error($userlink), 'SHOW CHARACTER SET;'); + $res = PMA_DBI_query('SHOW CHARACTER SET;'); $mysql_charsets = array(); - while ($row = PMA_mysql_fetch_array($res, MYSQL_ASSOC)) { + while ($row = PMA_DBI_fetch_assoc($res)) { $mysql_charsets[] = $row['Charset']; $mysql_charsets_maxlen[$row['Charset']] = $row['Maxlen']; $mysql_charsets_descriptions[$row['Charset']] = $row['Description']; @@ -16,15 +15,14 @@ if (PMA_MYSQL_INT_VERSION >= 40100){ @PMA_DBI_free_result($res); unset($res, $row); - $res = PMA_mysql_query('SHOW COLLATION;', $userlink) - or PMA_mysqlDie(PMA_mysql_error($userlink), 'SHOW COLLATION;'); + $res = PMA_DBI_query('SHOW COLLATION;'); $mysql_charsets_count = count($mysql_charsets); sort($mysql_charsets, SORT_STRING); $mysql_collations = array_flip($mysql_charsets); $mysql_default_collations = $mysql_collations_flat = array();; - while ($row = PMA_mysql_fetch_array($res, MYSQL_ASSOC)) { + while ($row = PMA_DBI_fetch_assoc($res)) { if (!is_array($mysql_collations[$row['Charset']])) { $mysql_collations[$row['Charset']] = array($row['Collation']); } else { @@ -233,9 +231,9 @@ if (PMA_MYSQL_INT_VERSION >= 40100){ // MySQL 4.1.0 does not support seperate charset settings // for databases. - $sql_query = 'SHOW CREATE DATABASE `' . $db . '`;'; - $res = PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query); - $row = PMA_mysql_fetch_row($res); + $res = PMA_DBI_query('SHOW CREATE DATABASE `' . $db . '`;'); + $row = PMA_DBI_fetch_row($res); + PMA_DBI_free_result($res); PMA_DBI_free_result($res); $tokenized = explode(' ', $row[1]); unset($row, $res, $sql_query); diff --git a/libraries/relation.lib.php b/libraries/relation.lib.php index 43e907f4da..9a49d396af 100644 --- a/libraries/relation.lib.php +++ b/libraries/relation.lib.php @@ -10,15 +10,15 @@ /** * Executes a query as controluser if possible, otherwise as normal user * - * @param string the query to execute - * @param boolean whether to display SQL error messages or not + * @param string the query to execute + * @param boolean whether to display SQL error messages or not * - * @return integer the result id + * @return integer the result id * - * @global string the URL of the page to show in case of error - * @global string the name of db to come back to - * @global integer the ressource id of DB connect as controluser - * @global array configuration infos about the relations stuff + * @global string the URL of the page to show in case of error + * @global string the name of db to come back to + * @global resource the resource id of DB connect as controluser + * @global array configuration infos about the relations stuff * * @access public * @@ -27,28 +27,20 @@ function PMA_query_as_cu($sql, $show_error = TRUE) { global $err_url_0, $db, $dbh, $cfgRelation; - if (isset($dbh)) { - PMA_mysql_select_db($cfgRelation['db'], $dbh); - $result = @PMA_mysql_query($sql, $dbh); - if (!$result && $show_error == TRUE) { - PMA_mysqlDie(mysql_error($dbh), $sql, '', $err_url_0); - } - PMA_mysql_select_db($db, $dbh); + PMA_DBI_select_db($cfgRelation['db'], $dbh); + if ($show_error) { + $result = PMA_DBI_query($sql, $dbh); } else { - PMA_mysql_select_db($cfgRelation['db']); - $result = @PMA_mysql_query($sql); - if ($result && $show_error == TRUE) { - PMA_mysqlDie('', $sql, '', $err_url_0); - } - PMA_mysql_select_db($db); + $result = PMA_DBI_try_query($sql, $dbh); } // end if... else... + PMA_DBI_select_db($db, $dbh); if ($result) { return $result; } else { return FALSE; } - } // end of the "PMA_query_as_cu()" function + } // end of the "PMA_query_as_cu()" function /** @@ -109,12 +101,12 @@ function PMA_getRelationsParam($verbose = FALSE) // example enable relations but not pdf... // I was thinking of checking if they have all required columns but I // fear it might be too slow - // PMA_mysql_select_db($cfgRelation['db']); + // PMA_DBI_select_db($cfgRelation['db']); $tab_query = 'SHOW TABLES FROM ' . PMA_backquote($cfgRelation['db']); $tab_rs = PMA_query_as_cu($tab_query, FALSE); - while ($curr_table = @PMA_mysql_fetch_array($tab_rs)) { + while ($curr_table = @PMA_DBI_fetch_assoc($tab_rs)) { if ($curr_table[0] == $cfg['Server']['bookmarktable']) { $cfgRelation['bookmark'] = $curr_table[0]; } else if ($curr_table[0] == $cfg['Server']['relation']) { @@ -150,7 +142,7 @@ function PMA_getRelationsParam($verbose = FALSE) $mime_field_mimetype = FALSE; $mime_field_transformation = FALSE; $mime_field_transformation_options = FALSE; - while ($curr_mime_field = @PMA_mysql_fetch_array($mime_rs)) { + while ($curr_mime_field = @PMA_DBI_fetch_assoc($mime_rs)) { if ($curr_mime_field[0] == 'mimetype') { $mime_field_mimetype = TRUE; } else if ($curr_mime_field[0] == 'transformation') { @@ -291,7 +283,7 @@ function PMA_getForeigners($db, $table, $column = '', $source = 'both') { } $relations = PMA_query_as_cu($rel_query); $i = 0; - while ($relrow = @PMA_mysql_fetch_array($relations)) { + while ($relrow = @PMA_DBI_fetch_assoc($relations)) { $field = $relrow['master_field']; $foreign[$field]['foreign_db'] = $relrow['foreign_db']; $foreign[$field]['foreign_table'] = $relrow['foreign_table']; @@ -303,8 +295,8 @@ function PMA_getForeigners($db, $table, $column = '', $source = 'both') { if (($source == 'both' || $source == 'innodb') && !empty($table)) { $show_create_table_query = 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table); - $show_create_table_res = PMA_mysql_query($show_create_table_query); - list(,$show_create_table) = PMA_mysql_fetch_row($show_create_table_res); + $show_create_table_res = PMA_DBI_query($show_create_table_query); + list(,$show_create_table) = PMA_DBI_fetch_row($show_create_table_res); $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table)); @@ -367,7 +359,7 @@ function PMA_getDisplayField($db, $table) { . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''; $disp_res = PMA_query_as_cu($disp_query); - $row = ($disp_res ? PMA_mysql_fetch_array($disp_res) : ''); + $row = ($disp_res ? PMA_DBI_fetch_assoc($disp_res) : ''); if (isset($row['display_field'])) { return $row['display_field']; } else { @@ -407,7 +399,7 @@ function PMA_getComments($db, $table = '') { } $i = 0; - while ($row = @PMA_mysql_fetch_array($com_rs)) { + while ($row = PMA_DBI_fetch_assoc($com_rs)) { $i++; $col = ($table != '' ? $row['column_name'] : $i); @@ -471,7 +463,7 @@ function PMA_setComment($db, $table, $key, $value, $removekey = '') { $test_rs = PMA_query_as_cu($test_qry); if ($test_rs && PMA_DBI_num_rows($test_rs) > 0) { - $row = @PMA_mysql_fetch_array($test_rs); + $row = PMA_DBI_fetch_assoc($test_rs); if (strlen($value) > 0 || strlen($row['mimetype']) > 0 || strlen($row['transformation']) > 0 || strlen($row['transformation_options']) > 0) { $upd_query = 'UPDATE ' . PMA_backquote($cfgRelation['column_info']) @@ -554,7 +546,7 @@ function PMA_getHistory($username) { $history = array(); - while ($row = @PMA_mysql_fetch_array($hist_rs)) { + while ($row = @PMA_DBI_fetch_assoc($hist_rs)) { $history[] = $row; } @@ -579,7 +571,7 @@ function PMA_purgeHistory($username) { $purge_rs = PMA_query_as_cu('SELECT timevalue FROM ' . PMA_backquote($cfgRelation['history']) . ' WHERE username = \'' . PMA_sqlAddSlashes($username) . '\' ORDER BY timevalue DESC LIMIT ' . $cfg['QueryHistoryMax'] . ', 1'); $i = 0; - $row = @PMA_mysql_fetch_array($purge_rs); + $row = PMA_DBI_fetch_row($purge_rs); if (is_array($row) && isset($row[0]) && $row[0] > 0) { $maxtime = $row[0]; @@ -609,7 +601,7 @@ function PMA_foreignDropdown($disp, $foreign_field, $foreign_display, $data, $ma $ret = '<option value=""></option>' . "\n"; $reloptions = array('content-id' => array(), 'id-content' => array()); - while ($relrow = @PMA_mysql_fetch_array($disp)) { + while ($relrow = @PMA_DBI_fetch_assoc($disp)) { $key = $relrow[$foreign_field]; if (strlen($relrow[$foreign_display]) <= $cfg['LimitChars']) { $value = (($foreign_display != FALSE) ? htmlspecialchars($relrow[$foreign_display]) : ''); diff --git a/libraries/transformations.lib.php b/libraries/transformations.lib.php index daca140f3f..726ff3fc7e 100644 --- a/libraries/transformations.lib.php +++ b/libraries/transformations.lib.php @@ -96,7 +96,7 @@ function PMA_getMIME($db, $table, $strict = false) { . ' AND (mimetype != \'\'' . (!$strict ? ' OR transformation != \'\' OR transformation_options != \'\'' : '') . ')'; $com_rs = PMA_query_as_cu($com_qry); - while ($row = @PMA_mysql_fetch_array($com_rs)) { + while ($row = @PMA_DBI_fetch_assoc($com_rs)) { $col = $row['column_name']; $mime[$col]['mimetype'] = $row['mimetype']; $mime[$col]['transformation'] = $row['transformation']; @@ -137,7 +137,7 @@ function PMA_setMIME($db, $table, $key, $mimetype, $transformation, $transformat $test_rs = PMA_query_as_cu($test_qry); if ($test_rs && PMA_DBI_num_rows($test_rs) > 0) { - $row = @PMA_mysql_fetch_array($test_rs); + $row = @PMA_DBI_fetch_assoc($test_rs); if (!$forcedelete && (strlen($mimetype) > 0 || strlen($transformation) > 0 || strlen($transformation_options) > 0 || strlen($row['comment']) > 0)) { $upd_query = 'UPDATE ' . PMA_backquote($cfgRelation['column_info']) @@ -71,10 +71,9 @@ if ($server > 0) { // if (!empty($cfg['Server']['socket']) && PMA_PHP_INT_VERSION >= 30010) { // $server_info .= ':' . $cfg['Server']['socket']; // } - $res = PMA_DBI_query('SELECT USER();'); - $row = PMA_DBI_fetch_row($res); - $mysql_cur_user_and_host = $row[0]; - $mysql_cur_user = substr($mysql_cur_user_and_host, 0, strrpos($mysql_cur_user_and_host, '@')); + $res = PMA_DBI_query('SELECT USER();'); + list($mysql_cur_user_and_host) = PMA_DBI_fetch_row($res); + $mysql_cur_user = substr($mysql_cur_user_and_host, 0, strrpos($mysql_cur_user_and_host, '@')); PMA_DBI_free_result($res); unset($res, $row); @@ -202,8 +201,7 @@ if ($server > 0) { // the first inexistant db name that we find, in most cases it's probably // the one he just dropped :) if (!$is_create_priv) { - $local_query = 'SELECT DISTINCT Db FROM mysql.db WHERE Create_priv = \'Y\' AND User = \'' . PMA_sqlAddslashes($mysql_cur_user) . '\''; - $rs_usr = PMA_DBI_try_query($local_query, $dbh); // Debug: or PMA_mysqlDie('', $local_query, FALSE); + $rs_usr = PMA_DBI_try_query('SELECT DISTINCT Db FROM mysql.db WHERE Create_priv = \'Y\' AND User = \'' . PMA_sqlAddslashes($mysql_cur_user) . '\';', $dbh); if ($rs_usr) { $re0 = '(^|(\\\\\\\\)+|[^\])'; // non-escaped wildcards $re1 = '(^|[^\])(\\\)+'; // escaped wildcards @@ -223,13 +221,11 @@ if ($server > 0) { // Finally, let's try to get the user's privileges by using SHOW // GRANTS... // Maybe we'll find a little CREATE priv there :) - $local_query = 'SHOW GRANTS FOR ' . $mysql_cur_user_and_host; - $rs_usr = PMA_DBI_try_query($local_query, $dbh); + $rs_usr = PMA_DBI_try_query('SHOW GRANTS FOR ' . $mysql_cur_user_and_host . ';', $dbh); if (!$rs_usr) { // OK, now we'd have to guess the user's hostname, but we // only try out the 'username'@'%' case. - $local_query = 'SHOW GRANTS FOR ' . $mysql_cur_user; - $rs_usr = PMA_DBI_try_query($local_query, $dbh); + $rs_usr = PMA_DBI_try_query('SHOW GRANTS FOR ' . $mysql_cur_user . ';', $dbh); } unset($local_query); if ($rs_usr) { diff --git a/mult_submits.inc.php b/mult_submits.inc.php index ab2de4e836..0a52e360b0 100644 --- a/mult_submits.inc.php +++ b/mult_submits.inc.php @@ -253,16 +253,16 @@ else if ($mult_btn == $strYes) { $sql_query .= $a_query . ';' . "\n"; if ($query_type != 'drop_db') { - PMA_mysql_select_db($db); + PMA_DBI_select_db($db); } - $result = @PMA_mysql_query($a_query) or PMA_mysqlDie('', $a_query, FALSE, $err_url); + $result = @PMA_DBI_query($a_query) or PMA_mysqlDie('', $a_query, FALSE, $err_url); } // end if } // end for if ($query_type == 'drop_tbl' || $query_type == 'drop_fld') { - PMA_mysql_select_db($db); - $result = @PMA_mysql_query($sql_query) or PMA_mysqlDie('', '', FALSE, $err_url); + PMA_DBI_select_db($db); + $result = PMA_DBI_query($sql_query); } elseif ($query_type == 'repair_tbl' || $query_type == 'analyze_tbl' || $query_type == 'check_tbl' diff --git a/pdf_pages.php b/pdf_pages.php index d00e854b03..aee4d04e31 100644 --- a/pdf_pages.php +++ b/pdf_pages.php @@ -95,7 +95,7 @@ if ($cfgRelation['pdfwork']) { // first put all the master tables at beginning // of the list, so they are near the center of // the schema - while (list(,$master_table) = mysql_fetch_row($master_tables_rs)) { + while (list(,$master_table) = PMA_DBI_fetch_row($master_tables_rs)) { $all_tables[] = $master_table; } @@ -221,9 +221,8 @@ if ($cfgRelation['pdfwork']) { // We will need an array of all tables in this db $selectboxall = array('--'); - $alltab_qry = 'SHOW TABLES FROM ' . PMA_backquote($db); - $alltab_rs = @PMA_mysql_query($alltab_qry) or PMA_mysqlDie('', $alltab_qry, '', $err_url_0); - while ($val = @PMA_mysql_fetch_array($alltab_rs)) { + $alltab_rs = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($db) . ';'); + while ($val = @PMA_DBI_fetch_row($alltab_rs)) { $selectboxall[] = $val[0]; } @@ -240,7 +239,7 @@ if ($cfgRelation['pdfwork']) { <input type="hidden" name="do" value="choosepage" /> <select name="chpage" onchange="this.form.submit()"> <?php - while ($curr_page = @PMA_mysql_fetch_array($page_rs)) { + while ($curr_page = PMA_DBI_fetch_assoc($page_rs)) { echo "\n" . ' ' . '<option value="' . $curr_page['page_nr'] . '"'; if (isset($chpage) && $chpage == $curr_page['page_nr']) { @@ -292,7 +291,7 @@ $array_sh_page = array(); $draginit = ''; $reset_draginit = ''; $i = 0; -while ($temp_sh_page = @PMA_mysql_fetch_array($page_rs)) { +while ($temp_sh_page = @PMA_DBI_fetch_assoc($page_rs)) { $array_sh_page[] = $temp_sh_page; } @@ -322,15 +321,17 @@ foreach($array_sh_page AS $key => $temp_sh_page) { $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($temp_sh_page['table_name'] ) . ' FROM ' . PMA_backquote($db); - $fields_rs = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url_0); + $fields_rs = PMA_DBI_query($local_query); + unset($local_query); $fields_cnt = PMA_DBI_num_rows($fields_rs); echo '<div id="table_' . $i . '" class="pdflayout_table"><u>' . $temp_sh_page['table_name'] . '</u>'; - while ($row = PMA_mysql_fetch_array($fields_rs)) { - echo "<br>".htmlspecialchars($row['Field'])."\n"; + while ($row = PMA_DBI_fetch_assoc($fields_rs)) { + echo '<br />' . htmlspecialchars($row['Field']) . "\n";s } echo '</div>' . "\n"; PMA_DBI_free_result($fields_rs); + unset($fields_rs); $i++; } diff --git a/pdf_schema.php b/pdf_schema.php index f56b1e54cc..1163fc4fe7 100644 --- a/pdf_schema.php +++ b/pdf_schema.php @@ -282,7 +282,7 @@ class PMA_PDF extends FPDF echo "\n"; require_once('./footer.inc.php'); - } // end of the "PMA_PDF_die()" function + } // end of the "PMA_PDF_die()" function /** @@ -312,7 +312,7 @@ class PMA_PDF extends FPDF . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND page_nr = \'' . $pdf_page_number . '\''; $test_rs = PMA_query_as_cu($test_query); - $pages = @PMA_mysql_fetch_array($test_rs); + $pages = @PMA_DBI_fetch_assoc($test_rs); $this->SetFont('', 'B', 14); $this->Cell(0,6, ucfirst($pages['page_descr']),'B',1,'C'); $this->SetFont('', ''); @@ -683,12 +683,12 @@ class PMA_RT_Table $this->table_name = $table_name; $sql = 'DESCRIBE ' . PMA_backquote($table_name); - $result = PMA_mysql_query($sql); + $result = PMA_DBI_try_query($sql); if (!$result || !PMA_DBI_num_rows($result)) { $pdf->PMA_PDF_die(sprintf($GLOBALS['strPdfInvalidTblName'], $table_name)); } // load fields - while ($row = PMA_mysql_fetch_array($result)) { + while ($row = PMA_DBI_fetch_row($result)) { $this->fields[] = $row[0]; } @@ -710,17 +710,16 @@ class PMA_RT_Table if (!$result || !PMA_DBI_num_rows($result)) { $pdf->PMA_PDF_die(sprintf($GLOBALS['strConfigureTableCoord'], $table_name)); } - list($this->x, $this->y) = PMA_mysql_fetch_array($result); + list($this->x, $this->y) = PMA_DBI_fetch_row($result); $this->x = (double) $this->x; $this->y = (double) $this->y; // displayfield $this->displayfield = PMA_getDisplayField($db, $table_name); // index - $sql = 'SHOW index FROM ' . PMA_backquote($table_name); - $result = PMA_mysql_query($sql); - if ($result && PMA_DBI_num_rows($result) > 0) { - while ($row = PMA_mysql_fetch_array($result)) { + $result = PMA_DBI_query('SHOW INDEX FROM ' . PMA_backquote($table_name) . ';'); + if (PMA_DBI_num_rows($result) > 0) { + while ($row = PMA_DBI_fetch_assoc($result)) { if ($row['Key_name'] == 'PRIMARY') { $this->primary[] = $row['Column_name']; } @@ -1043,7 +1042,7 @@ class PMA_RT . ' WHERE page_nr = ' . $pdf_page_number; $_name_rs = PMA_query_as_cu($_name_sql); if ($_name_rs) { - $_name_row = PMA_mysql_fetch_row($_name_rs); + $_name_row = PMA_DBI_fetch_row($_name_rs); $filename = $_name_row[0] . '.pdf'; } // i don't know if there is a chance for this to happen, but rather be on the safe side: @@ -1112,7 +1111,7 @@ class PMA_RT $pdf->PMA_PDF_die($GLOBALS['strPdfNoTables']); // die('No tables'); } - while ($curr_table = @PMA_mysql_fetch_array($tab_rs)) { + while ($curr_table = @PMA_DBI_fetch_assoc($tab_rs)) { $alltables[] = PMA_sqlAddslashes($curr_table['table_name']); //$intable = '\'' . implode('\', \'', $alltables) . '\''; } @@ -1200,7 +1199,7 @@ class PMA_RT // $norelations = TRUE; // if ($result && PMA_DBI_num_rows($result) > 0) { // $norelations = FALSE; -// while ($row = PMA_mysql_fetch_array($result)) { +// while ($row = PMA_DBI_fetch_assoc($result)) { // $this->PMA_RT_addRelation($row['master_table'] , $row['master_field'], $row['foreign_table'], $row['foreign_field']); // } // } @@ -1233,9 +1232,8 @@ function PMA_RT_DOC($alltables ){ $pdf->Cell(0,6,$i.' '. $table,0,1,'L',0,$pdf->PMA_links['doc'][$table]['-']); //$pdf->Ln(1); - $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table); - $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url); - while ($row = PMA_mysql_fetch_array($result)) { + $result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';'); + while ($row = PMA_DBI_fetch_assoc($result)) { $pdf->SetX(20); $field_name = $row['Field']; $pdf->PMA_links['doc'][$table][$field_name] =$pdf->AddLink(); @@ -1270,28 +1268,26 @@ function PMA_RT_DOC($alltables ){ $mime_map = PMA_getMIME($db, $table, true); } + /** * Gets table informations */ - $local_query = "SHOW TABLE STATUS LIKE '" . PMA_sqlAddslashes($table, TRUE) . "'"; - $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url); - $showtable = PMA_mysql_fetch_array($result); + $result = PMA_DBI_query('SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\';'); + $showtable = PMA_DBI_fetch_assoc($result); $num_rows = (isset($showtable['Rows']) ? $showtable['Rows'] : 0); $show_comment = (isset($showtable['Comment']) ? $showtable['Comment'] : ''); $create_time = (isset($showtable['Create_time']) ? PMA_localisedDate(strtotime($showtable['Create_time'])) : ''); $update_time = (isset($showtable['Update_time']) ? PMA_localisedDate(strtotime($showtable['Update_time'])) : ''); $check_time = (isset($showtable['Check_time']) ? PMA_localisedDate(strtotime($showtable['Check_time'])) : ''); - if ($result) { - PMA_DBI_free_result($result); - } + PMA_DBI_free_result($result); + unset($result); /** * Gets table keys and retains them */ - $local_query = 'SHOW KEYS FROM ' . PMA_backquote($table); - $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url); + $result = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';'); $primary = ''; $indexes = array(); $lastIndex = ''; @@ -1299,7 +1295,7 @@ function PMA_RT_DOC($alltables ){ $indexes_data = array(); $pk_array = array(); // will be use to emphasis prim. keys in the table // view - while ($row = PMA_mysql_fetch_array($result)) { + while ($row = PMA_DBI_fetch_assoc($result)) { // Backups the list of primary keys if ($row['Key_name'] == 'PRIMARY') { $primary .= $row['Column_name'] . ', '; @@ -1333,8 +1329,7 @@ function PMA_RT_DOC($alltables ){ /** * Gets fields properties */ - $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table); - $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url); + $result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';'); $fields_cnt = PMA_DBI_num_rows($result); @@ -1412,7 +1407,7 @@ function PMA_RT_DOC($alltables ){ } $pdf->SetFont('', ''); - while ($row = PMA_mysql_fetch_array($result)) { + while ($row = PMA_DBI_fetch_assoc($result)) { $bgcolor = ($i % 2) ?$GLOBALS['cfg']['BgcolorOne'] : $GLOBALS['cfg']['BgcolorTwo']; $i++; @@ -1518,7 +1513,7 @@ $all_tab_same_wide = (isset($all_tab_same_wide) && $all_tab_same_wide == 'on' $with_doc = (isset($with_doc) && $with_doc == 'on') ? 1 : 0; $orientation = (isset($orientation) && $orientation == 'P') ? 'P' : 'L'; $paper = isset($paper) ? $paper : 'A4'; -PMA_mysql_select_db($db); +PMA_DBI_select_db($db); $rt = new PMA_RT($pdf_page_number, $show_table_dimension, $show_color, $show_grid, $all_tab_same_wide, $orientation, $paper); ?> diff --git a/querywindow.php b/querywindow.php index e94118b466..b471c47fc9 100644 --- a/querywindow.php +++ b/querywindow.php @@ -283,10 +283,10 @@ if ($cfg['QueryFrame'] && $cfg['QueryFrameJS'] && $cfg['QueryFrameDebug']) { * Close MySql connections */ if (isset($dbh) && $dbh) { - @mysql_close($dbh); + DBI_close($dbh); } if (isset($userlink) && $userlink) { - @mysql_close($userlink); + DBI_close($userlink); } diff --git a/read_dump.php b/read_dump.php index 86c290f7a7..aa5a18e53c 100644 --- a/read_dump.php +++ b/read_dump.php @@ -148,8 +148,7 @@ if (!$cfg['AllowUserDropDatabase'] // Checks if the user is a Superuser // TODO: set a global variable with this information // loic1: optimized query - $result = @PMA_mysql_query('USE mysql'); - if (PMA_mysql_error()) { + if (!($result = PMA_DBI_select_db('mysql'))) { require_once('./header.inc.php'); PMA_mysqlDie($strNoDropDatabases, '', '', $err_url); } @@ -243,7 +242,7 @@ if ($sql_query != '') { } // Runs multiple queries - else if (PMA_mysql_select_db($db)) { + else if (PMA_DBI_select_db($db)) { $mult = TRUE; $info_msg = ''; $info_count = 0; @@ -257,7 +256,7 @@ if ($sql_query != '') { require('./sql.php'); } - $result = PMA_mysql_query($a_sql_query); + $result = PMA_DBI_try_query($a_sql_query); if ($result == FALSE) { // readdump failed if (isset($my_die) && $cfg['IgnoreMultiSubmitErrors']) { $my_die[] = "\n\n" . $a_sql_query; @@ -346,8 +345,8 @@ if ($goto == 'tbl_properties.php') { if (!isset($table)) { $goto = 'db_details.php'; } else { - PMA_mysql_select_db($db); - $is_table = @PMA_mysql_query('SHOW TABLES LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\''); + PMA_DBI_select_db($db); + $is_table = PMA_DBI_try_query('SHOW TABLES LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\''); if (!($is_table && @PMA_DBI_num_rows($is_table))) { $goto = 'db_details.php'; unset($table); @@ -361,7 +360,7 @@ if ($goto == 'db_details.php') { if (!isset($db)) { $goto = 'main.php'; } else { - $is_db = @PMA_mysql_select_db($db); + $is_db = @PMA_DBI_select_db($db); if (!$is_db) { $goto = 'main.php'; unset($db); diff --git a/server_common.inc.php b/server_common.inc.php index 6a8cdcd000..0e335aa8d2 100644 --- a/server_common.inc.php +++ b/server_common.inc.php @@ -35,10 +35,15 @@ require_once('./header.inc.php'); // priv CREATE TEMPORARY TABLES or LOCK TABLES can do a 'USE mysql' // (even if they cannot see the tables) -$is_superuser = @PMA_mysql_query('SELECT COUNT(*) FROM mysql.user', $userlink); +$is_superuser = PMA_DBI_try_query('SELECT COUNT(*) FROM mysql.user'); // now, select the mysql db if ($is_superuser) { - @PMA_mysql_query('USE mysql', $userlink); + PMA_DBI_free_result($is_superuser); + PMA_DBI_select_db('mysql', $userlink); + $is_superuser = TRUE; +} else { + $is_superuser = FALSE; } + ?> diff --git a/server_privileges.php b/server_privileges.php index 2d4f92eac1..942b9fbf77 100644 --- a/server_privileges.php +++ b/server_privileges.php @@ -73,10 +73,8 @@ function PMA_extractPrivInfo($row = '', $enableHTML = FALSE) array('Repl_client_priv', 'REPLICATION CLIENT', $GLOBALS['strPrivDescReplClient']) ); if (!empty($row) && isset($row['Table_priv'])) { - $sql_query = 'SHOW COLUMNS FROM `tables_priv` LIKE "Table_priv";'; - $res = PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query); - unset($sql_query); - $row1 = PMA_mysql_fetch_array($res, MYSQL_ASSOC); + $res = PMA_DBI_query('SHOW COLUMNS FROM `tables_priv` LIKE "Table_priv";', $userlink); + $row1 = PMA_DBI_fetch_assoc($res); PMA_DBI_free_result($res); $av_grants = explode ('\',\'' , substr($row1['Type'], 5, strlen($row1['Type']) - 7)); unset($row1); @@ -160,11 +158,9 @@ function PMA_displayPrivTable($db = '*', $table = '*', $submit = TRUE, $indent = } else { $sql_query = 'SELECT `Table_priv` FROM `tables_priv` WHERE `User` = "' . PMA_sqlAddslashes($username) . '" AND `Host` = "' . $hostname . '" AND `Db` = "' . $db . '" AND `Table_name` = "' . $table . '";'; } - $res = PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query); - if ($res) { - $row = PMA_mysql_fetch_array($res, MYSQL_ASSOC); - } - @PMA_DBI_free_result($res); + $res = PMA_DBI_query($sql_query); + $row = PMA_DBI_fetch_assoc($res); + PMA_DBI_free_result($res); } if (empty($row)) { if ($table == '*') { @@ -173,9 +169,8 @@ function PMA_displayPrivTable($db = '*', $table = '*', $submit = TRUE, $indent = } else if ($table == '*') { $sql_query = 'SHOW COLUMNS FROM `mysql`.`db`;'; } - $res = PMA_mysql_query($sql_query, $userlink) - or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query); - while ($row1 = PMA_mysql_fetch_row($res)) { + $res = PMA_DBI_query($sql_query); + while ($row1 = PMA_DBI_fetch_row($res)) { if (substr($row1[0], 0, 4) == 'max_') { $row[$row1[0]] = 0; } else { @@ -188,40 +183,32 @@ function PMA_displayPrivTable($db = '*', $table = '*', $submit = TRUE, $indent = } } if (isset($row['Table_priv'])) { - $sql_query = 'SHOW COLUMNS FROM `tables_priv` LIKE "Table_priv";'; - $res = PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query); - unset($sql_query); - $row1 = PMA_mysql_fetch_array($res, MYSQL_ASSOC); + $res = PMA_DBI_query('SHOW COLUMNS FROM `tables_priv` LIKE "Table_priv";', $userlink); + $row1 = PMA_DBI_fetch_assoc($res); PMA_DBI_free_result($res); $av_grants = explode ('\',\'' , substr($row1['Type'], strpos($row1['Type'], '(') + 2, strpos($row1['Type'], ')') - strpos($row1['Type'], '(') - 3)); - unset($row1); + unset($res, $row1); $users_grants = explode(',', $row['Table_priv']); foreach ($av_grants as $current_grant) { $row[$current_grant . '_priv'] = in_array($current_grant, $users_grants) ? 'Y' : 'N'; } - unset($row['Table_priv']); - unset($current_grant); - unset($av_grants); - unset($users_grants); - if ($res = PMA_mysql_query('SHOW COLUMNS FROM `' . $db . '`.`' . $table . '`;', $userlink)) { - $columns = array(); - while ($row1 = PMA_mysql_fetch_row($res)) { - $columns[$row1[0]] = array( - 'Select' => FALSE, - 'Insert' => FALSE, - 'Update' => FALSE, - 'References' => FALSE - ); - } - PMA_DBI_free_result($res); - unset($res); - unset($row1); + unset($row['Table_priv'], $current_grant, $av_grants, $users_grants); + $res = PMA_DBI_query('SHOW COLUMNS FROM `' . $db . '`.`' . $table . '`;'); + $columns = array(); + while ($row1 = PMA_DBI_fetch_row($res)) { + $columns[$row1[0]] = array( + 'Select' => FALSE, + 'Insert' => FALSE, + 'Update' => FALSE, + 'References' => FALSE + ); } + PMA_DBI_free_result($res); + unset($res, $row1); } if (!empty($columns)) { - $sql_query = 'SELECT `Column_name`, `Column_priv` FROM `columns_priv` WHERE `User` = "' . PMA_sqlAddslashes($username) . '" AND `Host` = "' . $hostname . '" AND `Db` = "' . $db . '" AND `Table_name` = "' . $table . '";'; - $res = PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query); - while ($row1 = PMA_mysql_fetch_row($res)) { + $res = PMA_DBI_query('SELECT `Column_name`, `Column_priv` FROM `columns_priv` WHERE `User` = "' . PMA_sqlAddslashes($username) . '" AND `Host` = "' . $hostname . '" AND `Db` = "' . $db . '" AND `Table_name` = "' . $table . '";'); + while ($row1 = PMA_DBI_fetch_row($res)) { $row1[1] = explode(',', $row1[1]); foreach ($row1[1] as $current) { $columns[$row1[0]][$current] = TRUE; @@ -487,9 +474,9 @@ function PMA_displayLoginInformationFields($mode = 'new', $indent = 0) . $spaces . ' </td>' . "\n" . $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n" . $spaces . ' <select name="pred_hostname" id="select_pred_hostname" title="' . $GLOBALS['strHost'] . '"' . "\n"; - $res = PMA_mysql_query('SELECT USER();', $userlink); - $row = @PMA_mysql_fetch_row($res); - @PMA_DBI_free_result($res); + $res = PMA_DBI_query('SELECT USER();'); + $row = PMA_DBI_fetch_row($res); + PMA_DBI_free_result($res); unset($res); if (!empty($row[0])) { $thishost = str_replace("'", '', substr($row[0], (strrpos($row[0], '@') + 1))); @@ -544,20 +531,19 @@ function PMA_displayLoginInformationFields($mode = 'new', $indent = 0) . $spaces . ' <input type="password" name="pma_pw2" id="text_pma_pw2" class="textfield" title="' . $GLOBALS['strReType'] . '" onchange="pred_password.value = \'userdefined\';" />' . "\n" . $spaces . ' </td>' . "\n" . $spaces . '</tr>' . "\n"; -} // end of the 'PMA_displayUserAndHostFields()' function +} // end of the 'PMA_displayUserAndHostFields()' function /** * Changes / copies a user, part I */ if (!empty($change_copy)) { - $local_query = 'SELECT * FROM `mysql`.`user` WHERE `User` = "' . PMA_sqlAddslashes($old_username) . '" AND `Host` = "' . $old_hostname . '";'; - $res = PMA_mysql_query($local_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $local_query); + $res = PMA_DBI_query('SELECT * FROM `mysql`.`user` WHERE `User` = "' . PMA_sqlAddslashes($old_username) . '" AND `Host` = "' . $old_hostname . '";'); if (!$res) { $message = $strNoUsersFound; unset($change_copy); } else { - $row = PMA_mysql_fetch_array($res, MYSQL_ASSOC); + $row = PMA_DBI_fetch_assoc($res); extract($row, EXTR_OVERWRITE); PMA_DBI_free_result($res); $queries = array(); @@ -585,17 +571,15 @@ if (!empty($adduser_submit) || !empty($change_copy)) { $hostname = ''; break; case 'thishost': - $res = PMA_mysql_query('SELECT USER();', $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), 'SELECT USER();'); - $row = PMA_mysql_fetch_row($res); + $res = PMA_DBI_query('SELECT USER();'); + $row = PMA_DBI_fetch_row($res); PMA_DBI_free_result($res); unset($res); $hostname = substr($row[0], (strrpos($row[0], '@') + 1)); unset($row); break; } - $local_query = 'SELECT "foo" FROM `user` WHERE `User` = "' . PMA_sqlAddslashes($username) . '" AND `Host` = "' . $hostname . '";'; - $res = PMA_mysql_query($local_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $local_query); - unset($local_query); + $res = PMA_DBI_query('SELECT "foo" FROM `user` WHERE `User` = "' . PMA_sqlAddslashes($username) . '" AND `Host` = "' . $hostname . '";'); if (PMA_DBI_affected_rows($userlink) == 1) { $message = sprintf($strUserAlreadyExists, '<i>\'' . $username . '\'@\'' . $hostname . '\'</i>'); $adduser = 1; @@ -639,7 +623,7 @@ if (!empty($adduser_submit) || !empty($change_copy)) { $real_sql_query .= ';'; $sql_query .= ';'; if (empty($change_copy)) { - PMA_mysql_query($real_sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query); + PMA_DBI_try_query($real_sql_query) or PMA_mysqlDie(PMA_DBI_getError(), $sql_query); $message = $strAddUserMessage; } else { $queries[] = $sql_query; @@ -655,17 +639,14 @@ if (!empty($adduser_submit) || !empty($change_copy)) { * Changes / copies a user, part III */ if (!empty($change_copy)) { - $local_query = 'SELECT * FROM `mysql`.`db` WHERE `User` = "' . PMA_sqlAddslashes($old_username) . '" AND `Host` = "' . $old_hostname . '";'; - $res = PMA_mysql_query($local_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $local_query); - while ($row = PMA_mysql_fetch_array($res, MYSQL_ASSOC)) { + $res = PMA_DBI_query('SELECT * FROM `mysql`.`db` WHERE `User` = "' . PMA_sqlAddslashes($old_username) . '" AND `Host` = "' . $old_hostname . '";'); + while ($row = PMA_DBI_fetch_assoc($res)) { $queries[] = 'GRANT ' . join(', ', PMA_extractPrivInfo($row)) . ' ON `' . $row['Db'] . '`.* TO "' . PMA_sqlAddslashes($username) . '"@"' . $hostname . '"' . ($row['Grant_priv'] == 'Y' ? ' WITH GRANT OPTION' : '') . ';'; } PMA_DBI_free_result($res); - $local_query = 'SELECT `Db`, `Table_name`, `Table_priv` FROM `mysql`.`tables_priv` WHERE `User` = "' . PMA_sqlAddslashes($old_username) . '" AND `Host` = "' . $old_hostname . '";'; - $res = PMA_mysql_query($local_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $local_query); - while ($row = PMA_mysql_fetch_array($res, MYSQL_ASSOC)) { - $local_query = 'SELECT `Column_name`, `Column_priv` FROM `mysql`.`columns_priv` WHERE `User` = "' . PMA_sqlAddslashes($old_username) . '" AND `Host` = "' . $old_hostname . '" AND `Db` = "' . $row['Db'] . '";'; - $res2 = PMA_mysql_query($local_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $local_query); + $res = PMA_DBI_query('SELECT `Db`, `Table_name`, `Table_priv` FROM `mysql`.`tables_priv` WHERE `User` = "' . PMA_sqlAddslashes($old_username) . '" AND `Host` = "' . $old_hostname . '";', $userlink); + while ($row = PMA_DBI_fetch_assoc($res)) { + $res2 = PMA_DBI_query('SELECT `Column_name`, `Column_priv` FROM `mysql`.`columns_priv` WHERE `User` = "' . PMA_sqlAddslashes($old_username) . '" AND `Host` = "' . $old_hostname . '" AND `Db` = "' . $row['Db'] . '";'); $tmp_privs1 = PMA_extractPrivInfo($row); $tmp_privs2 = array( 'Select' => array(), @@ -673,7 +654,7 @@ if (!empty($change_copy)) { 'Update' => array(), 'References' => array() ); - while ($row2 = PMA_mysql_fetch_array($res2, MYSQL_ASSOC)) { + while ($row2 = PMA_DBI_fetch_assoc($res2)) { $tmp_array = explode(',', $row2['Column_priv']); if (in_array('Select', $tmp_array)) { $tmp_privs2['Select'][] = $row2['Column_name']; @@ -735,12 +716,16 @@ if (!empty($update_privs)) { } } $sql_query2 .= ';'; - PMA_mysql_query($sql_query0, $userlink); // this query may fail, but this does not matter :o) - if (isset($sql_query1)) { - PMA_mysql_query($sql_query1, $userlink); // this one may fail, too... + if (!PMA_DBI_try_query($sql_query0)) { // this query may fail, but this does not matter :o) + unset($sql_query0); } - PMA_mysql_query($sql_query2, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query2); - $sql_query = $sql_query0 . ' ' . (isset($sql_query1) ? $sql_query1 . ' ' : '') . $sql_query2; + if (isset($sql_query1) && !PMA_DBI_try_query($sql_query1)) { // this one may fail, too... + unset($sql_query1); + } + PMA_DBI_query($sql_query2); + $sql_query = (isset($sql_query0) ? $sql_query0 . ' ' : '') + . (isset($sql_query1) ? $sql_query1 . ' ' : '') + . $sql_query2; $message = sprintf($strUpdatePrivMessage, '\'' . $username . '\'@\'' . $hostname . '\''); } @@ -752,9 +737,11 @@ if (!empty($revokeall)) { $db_and_table = PMA_backquote($dbname) . '.' . (empty($tablename) ? '*' : PMA_backquote($tablename)); $sql_query0 = 'REVOKE ALL PRIVILEGES ON ' . $db_and_table . ' FROM "' . $username . '"@"' . $hostname . '";'; $sql_query1 = 'REVOKE GRANT OPTION ON ' . $db_and_table . ' FROM "' . $username . '"@"' . $hostname . '";'; - PMA_mysql_query($sql_query0, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query0); - PMA_mysql_query($sql_query1, $userlink); // this one may fail, too... - $sql_query = $sql_query0 . ' ' . $sql_query1; + PMA_DBI_query($sql_query0); + if (!PMA_DBI_try_query($sql_query1)) { // this one may fail, too... + unset($sql_query1); + } + $sql_query = $sql_query0 . (isset($sql_query1) ? ' ' . $sql_query1 : ''); $message = sprintf($strRevokeMessage, '\'' . $username . '\'@\'' . $hostname . '\''); if (empty($tablename)) { unset($dbname); @@ -769,8 +756,8 @@ if (!empty($revokeall)) { */ if (!empty($change_pw)) { if ($nopass == 1) { - $sql_query = 'SET PASSWORD FOR "' . $username . '"@"' . $hostname . '" = ""'; - PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink)); + $sql_query = 'SET PASSWORD FOR "' . $username . '"@"' . $hostname . '" = "";'; + PMA_DBI_query($sql_query); $message = sprintf($strPasswordChanged, '\'' . $username . '\'@\'' . $hostname . '\''); } else if (empty($pma_pw) || empty($pma_pw2)) { $message = $strPasswordEmpty; @@ -783,7 +770,7 @@ if (!empty($change_pw)) { } $local_query = 'SET PASSWORD FOR "' . PMA_sqlAddslashes($username) . '"@"' . $hostname . '" = PASSWORD("' . PMA_sqlAddslashes($pma_pw) . '")'; $sql_query = 'SET PASSWORD FOR "' . PMA_sqlAddslashes($username) . '"@"' . $hostname . '" = PASSWORD("' . $hidden_pw . '")'; - PMA_mysql_query($local_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink)); + PMA_DBI_try_query($local_query) or PMA_mysqlDie(PMA_DBI_getError(), $sql_query); $message = sprintf($strPasswordChanged, '\'' . $username . '\'@\'' . $hostname . '\''); } } @@ -805,10 +792,10 @@ if (!empty($delete) || (!empty($change_copy) && $mode < 4)) { if ($mode == 2) { // The SHOW GRANTS query may fail if the user has not been loaded // into memory - $res = PMA_mysql_query('SHOW GRANTS FOR "' . PMA_sqlAddslashes($this_user) . '"@"' . $this_host . '";', $userlink); + $res = PMA_DBI_try_query('SHOW GRANTS FOR "' . PMA_sqlAddslashes($this_user) . '"@"' . $this_host . '";'); if ($res) { $queries[] = 'REVOKE ALL PRIVILEGES ON *.* FROM "' . PMA_sqlAddslashes($this_user) . '"@"' . $this_host . '";'; - while ($row = PMA_mysql_fetch_row($res)) { + while ($row = PMA_DBI_fetch_row($res)) { $this_table = substr($row[0], (strpos($row[0], 'ON') + 3), (strpos($row[0], ' TO ') - strpos($row[0], 'ON') - 3)); if ($this_table != '*.*') { $queries[] = 'REVOKE ALL PRIVILEGES ON ' . $this_table . ' FROM "' . PMA_sqlAddslashes($this_user) . '"@"' . $this_host . '";'; @@ -845,7 +832,7 @@ if (!empty($delete) || (!empty($change_copy) && $mode < 4)) { } foreach ($queries as $sql_query) { if ($sql_query{0} != '#') { - PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink)); + PMA_DBI_query($sql_query, $userlink); } } $sql_query = join("\n", $queries); @@ -862,7 +849,7 @@ if (!empty($delete) || (!empty($change_copy) && $mode < 4)) { if (!empty($change_copy)) { foreach ($queries as $sql_query) { if ($sql_query{0} != '#') { - PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink)); + PMA_DBI_query($sql_query); } } $message = $strSuccess; @@ -874,12 +861,9 @@ if (!empty($change_copy)) { * Reloads the privilege tables into memory */ if (!empty($flush_privileges)) { - $sql_query = 'FLUSH PRIVILEGES'; - if (@PMA_mysql_query($sql_query, $userlink)) { - $message = $strPrivilegesReloaded; - } else { - PMA_mysqlDie(PMA_mysql_error($userlink)); - } + $sql_query = 'FLUSH PRIVILEGES;'; + PMA_DBI_query($sql_query); + $message = $strPrivilegesReloaded; } @@ -900,7 +884,7 @@ if (empty($adduser) && empty($checkprivs)) { . '</h2>' . "\n"; $oldPrivTables = FALSE; if (PMA_MYSQL_INT_VERSION >= 40002) { - $res = PMA_mysql_query('SELECT `User`, `Host`, IF(`Password` = "", "N", "Y") AS "Password", `Select_priv`, `Insert_priv`, `Update_priv`, `Delete_priv`, `Create_priv`, `Drop_priv`, `Reload_priv`, `Shutdown_priv`, `Process_priv`, `File_priv`, `Grant_priv`, `References_priv`, `Index_priv`, `Alter_priv`, `Show_db_priv`, `Super_priv`, `Create_tmp_table_priv`, `Lock_tables_priv`, `Execute_priv`, `Repl_slave_priv`, `Repl_client_priv` FROM `user` ORDER BY `User` ASC, `Host` ASC;', $userlink); + $res = PMA_DBI_try_query('SELECT `User`, `Host`, IF(`Password` = ' . (PMA_MYSQL_INT_VERSION >= 40100 ? '_latin1 ' : '') . '"", "N", "Y") AS "Password", `Select_priv`, `Insert_priv`, `Update_priv`, `Delete_priv`, `Create_priv`, `Drop_priv`, `Reload_priv`, `Shutdown_priv`, `Process_priv`, `File_priv`, `Grant_priv`, `References_priv`, `Index_priv`, `Alter_priv`, `Show_db_priv`, `Super_priv`, `Create_tmp_table_priv`, `Lock_tables_priv`, `Execute_priv`, `Repl_slave_priv`, `Repl_client_priv` FROM `user` ORDER BY `User` ASC, `Host` ASC;'); if (!$res) { // the query failed! This may have two reasons: // - the user has not enough privileges @@ -909,7 +893,7 @@ if (empty($adduser) && empty($checkprivs)) { } } if (empty($res) || PMA_MYSQL_INT_VERSION < 40002) { - $res = PMA_mysql_query('SELECT `User`, `Host`, IF(`Password` = "", "N", "Y") AS "Password", `Select_priv`, `Insert_priv`, `Update_priv`, `Delete_priv`, `Index_priv`, `Alter_priv`, `Create_priv`, `Drop_priv`, `Grant_priv`, `References_priv`, `Reload_priv`, `Shutdown_priv`, `Process_priv`, `File_priv` FROM `user` ORDER BY `User` ASC, `Host` ASC;', $userlink); + $res = PMA_DBI_try_query('SELECT `User`, `Host`, IF(`Password` = ' . (PMA_MYSQL_INT_VERSION >= 40100 ? '_latin1 ' : '') . '"", "N", "Y") AS "Password", `Select_priv`, `Insert_priv`, `Update_priv`, `Delete_priv`, `Index_priv`, `Alter_priv`, `Create_priv`, `Drop_priv`, `Grant_priv`, `References_priv`, `Reload_priv`, `Shutdown_priv`, `Process_priv`, `File_priv` FROM `user` ORDER BY `User` ASC, `Host` ASC;'); if (!$res) { // the query failed! This may have two reasons: // - the user has not enough privileges @@ -919,7 +903,7 @@ if (empty($adduser) && empty($checkprivs)) { } if (!$res) { echo '<i>' . $strNoPrivileges . '</i>' . "\n"; - @PMA_DBI_free_result($res); + PMA_DBI_free_result($res); unset($res); } else { if ($oldPrivTables) { @@ -943,7 +927,7 @@ if (empty($adduser) && empty($checkprivs)) { . ' <th> ' . $strAction . ' </th>' . "\n"; echo ' </tr>' . "\n"; $useBgcolorOne = TRUE; - for ($i = 0; $row = PMA_mysql_fetch_array($res, MYSQL_ASSOC); $i++) { + for ($i = 0; $row = PMA_DBI_fetch_assoc($res); $i++) { echo ' <tr>' . "\n" . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '"><input type="checkbox" name="selected_usr[]" id="checkbox_sel_users_' . $i . '" value="' . htmlspecialchars($row['User'] . '@' . $row['Host']) . '"' . (empty($checkall) ? '' : ' checked="checked"') . ' /></td>' . "\n" . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '"><label for="checkbox_sel_users_' . $i . '">' . (empty($row['User']) ? '<span style="color: #FF0000">' . $strAny . '</span>' : htmlspecialchars($row['User'])) . '</label></td>' . "\n" @@ -1017,8 +1001,8 @@ if (empty($adduser) && empty($checkprivs)) { } } echo '</h2>' . "\n"; - $res = PMA_mysql_query('SELECT "foo" FROM `user` WHERE `User` = "' . PMA_sqlAddslashes($username) . '" AND `Host` = "' . $hostname . '";', $userlink); - if (PMA_DBI_affected_rows($userlink) <= 0) { + $res = PMA_DBI_query('SELECT "foo" FROM `user` WHERE `User` = "' . PMA_sqlAddslashes($username) . '" AND `Host` = "' . $hostname . '";'); + if (PMA_DBI_affected_rows($userlink) < 1) { echo $strUserNotFound; require_once('./footer.inc.php'); } @@ -1056,7 +1040,7 @@ if (empty($adduser) && empty($checkprivs)) { } else { $sql_query = 'SELECT `Table_name`, `Table_priv`, IF(`Column_priv` = "", 0, 1) AS "Column_priv" FROM `tables_priv` WHERE `Host` = "' . $hostname . '" AND `User` = "' . PMA_sqlAddslashes($username) . '" AND `Db` = "' . $dbname . '" ORDER BY `Table_name` ASC;'; } - $res = PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query); + $res = PMA_DBI_query($sql_query); if (PMA_DBI_affected_rows($userlink) == 0) { echo ' <tr>' . "\n" . ' <td bgcolor="' . $cfg['BgcolorOne'] . '" colspan="6"><center><i>' . $strNone . '</i></center></td>' . "\n" @@ -1064,11 +1048,11 @@ if (empty($adduser) && empty($checkprivs)) { } else { $useBgcolorOne = TRUE; if (empty($dbname)) { - $res2 = PMA_mysql_query('SELECT `Db` FROM `tables_priv` WHERE `Host` = "' . $hostname . '" AND `User` = "' . PMA_sqlAddslashes($username) . '" GROUP BY `Db` ORDER BY `Db` ASC;') or PMA_mysqlDie(PMA_mysql_error($userlink), 'SELECT `Db` FROM `tables_priv` WHERE `Host` = "' . $hostname . '" AND `User` = "' . PMA_sqlAddslashes($username) . '" GROUP BY `Db` ORDER BY `Db` ASC;'); - $row2 = PMA_mysql_fetch_array($res2, MYSQL_ASSOC); + $res2 = PMA_DBI_query('SELECT `Db` FROM `tables_priv` WHERE `Host` = "' . $hostname . '" AND `User` = "' . PMA_sqlAddslashes($username) . '" GROUP BY `Db` ORDER BY `Db` ASC;'); + $row2 = PMA_DBI_fetch_assoc($res2); } $found_rows = array(); - while ($row = PMA_mysql_fetch_array($res, MYSQL_ASSOC)) { + while ($row = PMA_DBI_fetch_assoc($res)) { while (empty($dbname) && $row2 && $row['Db'] > $row2['Db']) { $found_rows[] = $row2['Db']; @@ -1083,7 +1067,7 @@ if (empty($adduser) && empty($checkprivs)) { . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '"><a href="server_privileges.php?' . $url_query . '&username=' . urlencode($username) . '&hostname=' . urlencode($hostname) . '&dbname=' . urlencode($row2['Db']) . '">' . $strEdit . '</a></td>' . "\n" . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '"><a href="server_privileges.php?' . $url_query . '&username=' . urlencode($username) . '&hostname=' . urlencode($hostname) . '&dbname=' . urlencode($row2['Db']) . '&revokeall=1">' . $strRevoke . '</a></td>' . "\n" . ' </tr>' . "\n"; - $row2 = PMA_mysql_fetch_array($res2, MYSQL_ASSOC); + $row2 = PMA_DBI_fetch_assoc($res2); $useBgcolorOne = !$useBgcolorOne; } // end while $found_rows[] = empty($dbname) ? $row['Db'] : $row['Table_name']; @@ -1099,7 +1083,7 @@ if (empty($adduser) && empty($checkprivs)) { || (!empty($dbname) && $row['Column_priv'])) { echo $strYes; if (empty($dbname)) { - $row2 = PMA_mysql_fetch_array($res2, MYSQL_ASSOC); + $row2 = PMA_DBI_fetch_assoc($res2); } } else { echo $strNo; @@ -1125,7 +1109,7 @@ if (empty($adduser) && empty($checkprivs)) { . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '"><a href="server_privileges.php?' . $url_query . '&username=' . urlencode($username) . '&hostname=' . urlencode($hostname) . '&dbname=' . urlencode($row2['Db']) . '">' . $strEdit . '</a></td>' . "\n" . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '"><a href="server_privileges.php?' . $url_query . '&username=' . urlencode($username) . '&hostname=' . urlencode($hostname) . '&dbname=' . urlencode($row2['Db']) . '&revokeall=1">' . $strRevoke . '</a></td>' . "\n" . ' </tr>' . "\n"; - $row2 = PMA_mysql_fetch_array($res2, MYSQL_ASSOC); + $row2 = PMA_DBI_fetch_assoc($res2); $useBgcolorOne = !$useBgcolorOne; } // end while @@ -1146,9 +1130,9 @@ if (empty($adduser) && empty($checkprivs)) { . ' <input type="hidden" name="hostname" value="' . htmlspecialchars($hostname) . '" />' . "\n"; if (empty($dbname)) { echo ' <label for="text_dbname">' . $strAddPrivilegesOnDb . ':</label>' . "\n"; - $res = PMA_mysql_query('SHOW DATABASES;', $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), 'SHOW DATABASES;'); + $res = PMA_DBI_query('SHOW DATABASES;'); $pred_db_array = array(); - while ($row = PMA_mysql_fetch_row($res)) { + while ($row = PMA_DBI_fetch_row($res)) { if (!isset($found_rows) || !in_array($row[0], $found_rows)) { $pred_db_array[] = $row[0]; } @@ -1168,9 +1152,9 @@ if (empty($adduser) && empty($checkprivs)) { } else { echo ' <input type="hidden" name="dbname" value="' . htmlspecialchars($dbname) . '"/>' . "\n" . ' <label for="text_tablename">' . $strAddPrivilegesOnTbl . ':</label>' . "\n"; - if ($res = @PMA_mysql_query('SHOW TABLES FROM ' . PMA_backquote($dbname) . ';', $userlink)) { + if ($res = PMA_DBI_try_query('SHOW TABLES FROM ' . PMA_backquote($dbname) . ';')) { $pred_tbl_array = array(); - while ($row = PMA_mysql_fetch_row($res)) { + while ($row = PMA_DBI_fetch_row($res)) { if (!isset($found_rows) || !in_array($row[0], $found_rows)) { $pred_tbl_array[] = $row[0]; } @@ -1318,19 +1302,19 @@ if (empty($adduser) && empty($checkprivs)) { // Starting with MySQL 4.0.0, we may use UNION SELECTs and this makes // the job much easier here! $sql_query = '(SELECT `User`, `Host`, `Db`, `Select_priv`, `Insert_priv`, `Update_priv`, `Delete_priv`, `Create_priv`, `Drop_priv`, `Grant_priv`, `References_priv` FROM `db` WHERE "' . $checkprivs . '" LIKE `Db` AND NOT (`Select_priv` = "N" AND `Insert_priv` = "N" AND `Update_priv` = "N" AND `Delete_priv` = "N" AND `Create_priv` = "N" AND `Drop_priv` = "N" AND `Grant_priv` = "N" AND `References_priv` = "N")) UNION (SELECT `User`, `Host`, "*" AS "Db", `Select_priv`, `Insert_priv`, `Update_priv`, `Delete_priv`, `Create_priv`, `Drop_priv`, `Grant_priv`, `References_priv` FROM `user` WHERE NOT (`Select_priv` = "N" AND `Insert_priv` = "N" AND `Update_priv` = "N" AND `Delete_priv` = "N" AND `Create_priv` = "N" AND `Drop_priv` = "N" AND `Grant_priv` = "N" AND `References_priv` = "N")) ORDER BY `User` ASC, `Host` ASC, `Db` ASC;'; - $res = PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query); - $row = PMA_mysql_fetch_array($res, MYSQL_ASSOC); + $res = PMA_DBI_query($sql_query); + $row = PMA_DBI_fetch_assoc($res); if ($row) { $found = TRUE; } } else { // With MySQL 3, we need 2 seperate queries here. $sql_query = 'SELECT * FROM `user` WHERE NOT (`Select_priv` = "N" AND `Insert_priv` = "N" AND `Update_priv` = "N" AND `Delete_priv` = "N" AND `Create_priv` = "N" AND `Drop_priv` = "N" AND `Grant_priv` = "N" AND `References_priv` = "N") ORDER BY `User` ASC, `Host` ASC;'; - $res1 = PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query); - $row1 = PMA_mysql_fetch_array($res1, MYSQL_ASSOC); + $res1 = PMA_DBI_query($sql_query); + $row1 = PMA_DBI_fetch_assoc($res1); $sql_query = 'SELECT * FROM `db` WHERE "' . $checkprivs . '" LIKE `Db` AND NOT (`Select_priv` = "N" AND `Insert_priv` = "N" AND `Update_priv` = "N" AND `Delete_priv` = "N" AND `Create_priv` = "N" AND `Drop_priv` = "N" AND `Grant_priv` = "N" AND `References_priv` = "N") ORDER BY `User` ASC, `Host` ASC;'; - $res2 = PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query); - $row2 = PMA_mysql_fetch_array($res2, MYSQL_ASSOC); + $res2 = PMA_DBI_query($sql_query); + $row2 = PMA_DBI_fetch_assoc($res2); if ($row1 || $row2) { $found = TRUE; } @@ -1344,7 +1328,7 @@ if (empty($adduser) && empty($checkprivs)) { $current_host = $row['Host']; while ($row && $current_user == $row['User'] && $current_host == $row['Host']) { $current_privileges[] = $row; - $row = PMA_mysql_fetch_array($res, MYSQL_ASSOC); + $row = PMA_DBI_fetch_assoc($res); } } else { $current_privileges = array(); @@ -1352,7 +1336,7 @@ if (empty($adduser) && empty($checkprivs)) { $current_user = $row1['User']; $current_host = $row1['Host']; $current_privileges = array($row1); - $row1 = PMA_mysql_fetch_array($res1, MYSQL_ASSOC); + $row1 = PMA_DBI_fetch_assoc($res1); } else { $current_user = $row2['User']; $current_host = $row2['Host']; @@ -1360,7 +1344,7 @@ if (empty($adduser) && empty($checkprivs)) { } while ($row2 && $current_user == $row2['User'] && $current_host == $row2['Host']) { $current_privileges[] = $row2; - $row2 = PMA_mysql_fetch_array($res2, MYSQL_ASSOC); + $row2 = PMA_DBI_fetch_assoc($res2); } } echo ' <tr>' . "\n" diff --git a/server_processlist.php b/server_processlist.php index 50baf258e9..e32d5a2e8b 100644 --- a/server_processlist.php +++ b/server_processlist.php @@ -13,8 +13,7 @@ require_once('./server_common.inc.php'); * Kills a selected process */ if (!empty($kill)) { - $sql_query = 'KILL ' . $kill . ';'; - if (@PMA_mysql_query($sql_query, $userlink)) { + if (PMA_DBI_try_query('KILL ' . $kill . ';')) { $message = sprintf($strThreadSuccessfullyKilled, $kill); } else { $message = sprintf($strCouldNotKill, $kill); @@ -40,9 +39,8 @@ echo '<h2>' . "\n" * Sends the query and buffers the result */ $serverProcesses = array(); -$sql_query = 'SHOW' . (empty($full) ? '' : ' FULL') . ' PROCESSLIST;'; -$res = @PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query); -while ($row = PMA_mysql_fetch_array($res, MYSQL_ASSOC)) { +$res = PMA_DBI_query('SHOW' . (empty($full) ? '' : ' FULL') . ' PROCESSLIST;'); +while ($row = PMA_DBI_fetch_assoc($res)) { $serverProcesses[] = $row; } @PMA_DBI_free_result($res); diff --git a/server_status.php b/server_status.php index 79d108087c..38335dcfb1 100644 --- a/server_status.php +++ b/server_status.php @@ -22,9 +22,8 @@ if (!empty($innodbstatus)) { echo '<h2>' . "\n" . ' ' . $strInnodbStat . "\n" . '</h2>' . "\n"; - $sql_query = 'SHOW INNODB STATUS;'; - $res = PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query); - $row = PMA_mysql_fetch_row($res); + $res = PMA_DBI_query('SHOW INNODB STATUS;'); + $row = PMA_DBI_fetch_row($res); echo '<pre>' . "\n" . htmlspecialchars($row[0]) . "\n" . '</pre>' . "\n"; @@ -52,25 +51,23 @@ if (!$is_superuser && !$cfg['ShowMysqlInfo']) { /** * Sends the query and buffers the result */ -$res = @PMA_mysql_query('SHOW STATUS;', $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), 'SHOW STATUS;'); -while ($row = PMA_mysql_fetch_row($res)) { +$res = PMA_DBI_query('SHOW STATUS;'); +while ($row = PMA_DBI_fetch_row($res)) { $serverStatus[$row[0]] = $row[1]; } -@PMA_DBI_free_result($res); -unset($res); -unset($row); +PMA_DBI_free_result($res); +unset($res, $row); /** * Displays the page */ //Uptime calculation -$res = @PMA_mysql_query('SELECT UNIX_TIMESTAMP() - ' . $serverStatus['Uptime'] . ';'); -$row = PMA_mysql_fetch_row($res); +$res = PMA_DBI_query('SELECT UNIX_TIMESTAMP() - ' . $serverStatus['Uptime'] . ';'); +$row = PMA_DBI_fetch_row($res); echo sprintf($strServerStatusUptime, PMA_timespanFormat($serverStatus['Uptime']), PMA_localisedDate($row[0])) . "\n"; PMA_DBI_free_result($res); -unset($res); -unset($row); +unset($res, $row); //Get query statistics $queryStats = array(); $tmp_array = $serverStatus; @@ -272,9 +269,9 @@ if (!empty($serverStatus)) { </li> <?php } -$res = PMA_mysql_query('SHOW VARIABLES LIKE "have_innodb";', $userlink); +$res = PMA_DBI_query('SHOW VARIABLES LIKE "have_innodb";'); if ($res) { - $row = PMA_mysql_fetch_row($res); + $row = PMA_DBI_fetch_row($res); if (!empty($row[1]) && $row[1] == 'YES') { ?> <br /> diff --git a/server_variables.php b/server_variables.php index cf184eb80c..777737dc6e 100644 --- a/server_variables.php +++ b/server_variables.php @@ -36,22 +36,25 @@ if (!$is_superuser && !$cfg['ShowMysqlVars']) { * Sends the queries and buffers the results */ if (PMA_MYSQL_INT_VERSION >= 40003) { - $res = @PMA_mysql_query('SHOW SESSION VARIABLES;', $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), 'SHOW SESSION VARIABLES;'); - while ($row = PMA_mysql_fetch_row($res)) { + $res = PMA_DBI_query('SHOW SESSION VARIABLES;'); + while ($row = PMA_DBI_fetch_row($res)) { $serverVars[$row[0]] = $row[1]; } - @PMA_DBI_free_result($res); - $res = @PMA_mysql_query('SHOW GLOBAL VARIABLES;', $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), 'SHOW GLOBAL VARIABLES;'); - while ($row = PMA_mysql_fetch_row($res)) { + PMA_DBI_free_result($res); + unset($res, $row); + $res = PMA_DBI_query('SHOW GLOBAL VARIABLES;'); + while ($row = PMA_DBI_fetch_row($res)) { $serverVarsGlobal[$row[0]] = $row[1]; } - @PMA_DBI_free_result($res); + PMA_DBI_free_result($res); + unset($res, $row); } else { - $res = @PMA_mysql_query('SHOW VARIABLES;', $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), 'SHOW VARIABLES;'); - while ($row = PMA_mysql_fetch_row($res)) { + $res = PMA_DBI_query('SHOW VARIABLES;'); + while ($row = PMA_DBI_fetch_row($res)) { $serverVars[$row[0]] = $row[1]; } - @PMA_DBI_free_result($res); + PMA_DBI_free_result($res); + unset($res, $row); } unset($res); unset($row); @@ -59,8 +59,7 @@ if (!defined('PMA_CHK_DROP') // Checks if the user is a Superuser // TODO: set a global variable with this information // loic1: optimized query - $result = @PMA_mysql_query('USE mysql'); - if (PMA_mysql_error()) { + if (!($result = PMA_DBI_select_db('mysql'))) { require_once('./header.inc.php'); PMA_mysqlDie($strNoDropDatabases, '', '', $err_url); } // end if @@ -285,7 +284,7 @@ else { $full_sql_query = $sql_query; } // end if...else - PMA_mysql_select_db($db); + PMA_DBI_select_db($db); // If the query is a DELETE query with no WHERE clause, get the number of // rows that will be deleted (mysql_affected_rows will always return 0 in @@ -293,9 +292,9 @@ else { if ($is_delete && preg_match('@^DELETE([[:space:]].+)?([[:space:]]FROM[[:space:]](.+))$@i', $sql_query, $parts) && !preg_match('@[[:space:]]WHERE[[:space:]]@i', $parts[3])) { - $cnt_all_result = @PMA_mysql_query('SELECT COUNT(*) as count' . $parts[2]); + $cnt_all_result = @PMA_DBI_try_query('SELECT COUNT(*) as count' . $parts[2]); if ($cnt_all_result) { - $num_rows = PMA_mysql_result($cnt_all_result, 0, 'count'); + $num_rows = PMA_DBI_result($cnt_all_result, 0, 'count'); PMA_DBI_free_result($cnt_all_result); } else { $num_rows = 0; @@ -314,7 +313,7 @@ else { list($usec, $sec) = explode(' ',microtime()); $querytime_before = ((float)$usec + (float)$sec); - $result = @PMA_mysql_query($full_sql_query); + $result = @PMA_DBI_try_query($full_sql_query); list($usec, $sec) = explode(' ',microtime()); $querytime_after = ((float)$usec + (float)$sec); @@ -322,14 +321,14 @@ else { $GLOBALS['querytime'] = $querytime_after - $querytime_before; // Displays an error message if required and stop parsing the script - if (PMA_mysql_error()) { - $error = PMA_mysql_error(); + if ($error = PMA_DBI_getError()) { require_once('./header.inc.php'); $full_err_url = (preg_match('@^(db_details|tbl_properties)@', $err_url)) ? $err_url . '&show_query=1&sql_query=' . urlencode($sql_query) : $err_url; PMA_mysqlDie($error, $full_sql_query, '', $full_err_url); } + unset($error); // Gets the number of rows affected/returned // (This must be done immediately after the query because @@ -343,15 +342,14 @@ else { // Checks if the current database has changed // This could happen if the user sends a query like "USE `database`;" - $res = PMA_mysql_query('SELECT DATABASE() AS "db";'); - $row = PMA_mysql_fetch_array($res); - if (is_array($row) && isset($row['db']) && $db != $row['db']) { - $db = $row['db']; + $res = PMA_DBI_query('SELECT DATABASE() AS "db";'); + $row = PMA_DBI_fetch_row($res); + if (is_array($row) && isset($row[0]) && $db != $row[0]) { + $db = $row[0]; $reload = 1; } @PMA_DBI_free_result($res); - unset($res); - unset($row); + unset($res, $row); // tmpfile remove after convert encoding appended by Y.Kawada if (function_exists('PMA_kanji_file_conv') @@ -457,15 +455,16 @@ else { //DEBUG echo "trace cq=" . $count_query . "<br/>"; if (PMA_MYSQL_INT_VERSION < 40000) { - if ($cnt_all_result = PMA_mysql_query($count_query)) { + if ($cnt_all_result = PMA_DBI_try_query($count_query)) { if ($is_group && $count_what == '*') { $unlim_num_rows = @PMA_DBI_num_rows($cnt_all_result); } else { - $unlim_num_rows = PMA_mysql_result($cnt_all_result, 0, 'count'); + $unlim_num_rows = PMA_DBI_fetch_assoc($cnt_all_result); + $unlim_num_rows = $unlim_num_rows['count']; } PMA_DBI_free_result($cnt_all_result); } else { - if (mysql_error()) { + if (PMA_DBI_getError()) { // there are some cases where the generated // count_query (for MySQL 3) is wrong, @@ -477,7 +476,7 @@ else { } } } else { - PMA_mysql_query($count_query); + PMA_DBI_query($count_query); // if (mysql_error()) { // void. I tried the case // (SELECT `User`, `Host`, `Db`, `Select_priv` FROM `db`) @@ -487,8 +486,8 @@ else { // and although the generated count_query is wrong // the SELECT FOUND_ROWS() work! // } - $cnt_all_result = PMA_mysql_query('SELECT FOUND_ROWS() as count'); - $unlim_num_rows = PMA_mysql_result($cnt_all_result,0,'count'); + $cnt_all_result = PMA_DBI_query('SELECT FOUND_ROWS() as count;'); + list($unlim_num_rows) = PMA_DBI_fetch_row($cnt_all_result); } } // end else "just browsing" @@ -558,7 +557,7 @@ else { if (!isset($table)) { $goto = 'db_details.php'; } else { - $is_table = @PMA_mysql_query('SHOW TABLES LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\''); + $is_table = @PMA_DBI_query('SHOW TABLES LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\';'); if (!($is_table && @PMA_DBI_num_rows($is_table))) { $goto = 'db_details.php'; unset($table); @@ -572,7 +571,7 @@ else { if (!isset($db)) { $goto = 'main.php'; } else { - $is_db = @PMA_mysql_select_db($db); + $is_db = @PMA_DBI_select_db($db); if (!$is_db) { $goto = 'main.php'; unset($db); @@ -623,10 +622,8 @@ else { // Gets the list of fields properties if (isset($result) && $result) { - while ($field = PMA_mysql_fetch_field($result)) { - $fields_meta[] = $field; - } - $fields_cnt = count($fields_meta); + $fields_meta = PMA_DBI_get_fields_meta($result); + $fields_cnt = count($fields_meta); } // Display previous update query (from tbl_replace) diff --git a/tbl_addfield.php b/tbl_addfield.php index ee2d5fdb79..5b301a5e12 100644 --- a/tbl_addfield.php +++ b/tbl_addfield.php @@ -101,11 +101,10 @@ if (isset($submit)) { // To allow replication, we first select the db to use and then run queries // on this db. - $sql_query = 'USE ' . PMA_backquote($db); - $result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', '', '', $err_url); + PMA_DBI_select_db($db) or PMA_mysqlDie(PMA_getError(), 'USE ' . PMA_backquotes($db), '', $err_url); $sql_query = 'ALTER TABLE ' . PMA_backquote($table) . ' ADD ' . $query; - $error_create = false; - $result = PMA_mysql_query($sql_query) or $error_create = true; + $error_create = FALSE; + PMA_DBI_try_query($sql_query) or $error_create = TRUE; if ($error_create == false) { @@ -123,8 +122,8 @@ if (isset($submit)) { } // end for $primary = preg_replace('@, $@', '', $primary); if (!empty($primary)) { - $sql_query = 'ALTER TABLE ' . PMA_backquote($table) . ' ADD PRIMARY KEY (' . $primary . ')'; - $result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', '', '', $err_url); + $sql_query = 'ALTER TABLE ' . PMA_backquote($table) . ' ADD PRIMARY KEY (' . $primary . ');'; + $result = PMA_DBI_query($sql_query); $sql_query_cpy .= "\n" . $sql_query . ';'; } } // end if @@ -142,7 +141,7 @@ if (isset($submit)) { $index = preg_replace('@, $@', '', $index); if (!empty($index)) { $sql_query = 'ALTER TABLE ' . PMA_backquote($table) . ' ADD INDEX (' . $index . ')'; - $result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', '', '', $err_url); + $result = PMA_DBI_query($sql_query); $sql_query_cpy .= "\n" . $sql_query . ';'; } } // end if @@ -160,7 +159,7 @@ if (isset($submit)) { $unique = preg_replace('@, $@', '', $unique); if (!empty($unique)) { $sql_query = 'ALTER TABLE ' . PMA_backquote($table) . ' ADD UNIQUE (' . $unique . ')'; - $result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', '', '', $err_url); + $result = PMA_DBI_query($sql_query); $sql_query_cpy .= "\n" . $sql_query . ';'; } } // end if @@ -177,7 +176,7 @@ if (isset($submit)) { $fulltext = preg_replace('@, $@', '', $fulltext); if (!empty($fulltext)) { $sql_query = 'ALTER TABLE ' . PMA_backquote($table) . ' ADD FULLTEXT (' . $fulltext . ')'; - $result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', '', '', $err_url); + $result = PMA_DBI_query($sql_query); $sql_query_cpy .= "\n" . $sql_query . ';'; } } // end if diff --git a/tbl_alter.php b/tbl_alter.php index f9759f60e6..1f5b6d278c 100644 --- a/tbl_alter.php +++ b/tbl_alter.php @@ -72,14 +72,13 @@ if (isset($submit)) { // To allow replication, we first select the db to use and then run queries // on this db. - $sql_query = 'USE ' . PMA_backquote($db); - $result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', '', '', $err_url); + PMA_DBI_select_db($db) or PMA_mysqlDie(PMA_DBI_getError(), 'USE ' . PMA_backquote($db) . ';', '', $err_url); // Optimization fix - 2 May 2001 - Robbat2 $sql_query = 'ALTER TABLE ' . PMA_backquote($table) . ' CHANGE ' . $query; - $error_create = false; - $result = PMA_mysql_query($sql_query) or $error_create = true; + $error_create = FALSE; + $result = PMA_DBI_try_query($sql_query) or $error_create = TRUE; - if ($error_create == false) { + if ($error_create == FALSE) { $message = $strTable . ' ' . htmlspecialchars($table) . ' ' . $strHasBeenAltered; $btnDrop = 'Fake'; @@ -175,9 +174,8 @@ if ($abort == FALSE) { } else { $field = PMA_sqlAddslashes($selected[$i], TRUE); } - $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db) . " LIKE '$field'"; - $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url); - $fields_meta[] = PMA_mysql_fetch_array($result); + $result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db) . ' LIKE \'' . $field . '\';'); + $fields_meta[] = PMA_DBI_fetch_assoc($result); PMA_DBI_free_result($result); } diff --git a/tbl_change.php b/tbl_change.php index 52a77dd01d..08c99d8eef 100644 --- a/tbl_change.php +++ b/tbl_change.php @@ -78,8 +78,8 @@ echo '<br />'; /** * Get the list of the fields of the current table */ -PMA_mysql_select_db($db); -$table_def = PMA_mysql_query('SHOW FIELDS FROM ' . PMA_backquote($table)); +PMA_DBI_select_db($db); +$table_def = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';'); if (isset($primary_key)) { if (is_array($primary_key)) { $primary_key_array = $primary_key; @@ -90,11 +90,10 @@ if (isset($primary_key)) { $row = array(); $result = array(); foreach($primary_key_array AS $rowcount => $primary_key) { - $local_query = 'SELECT * FROM ' . PMA_backquote($table) . ' WHERE ' . $primary_key; - $result[$rowcount] = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url); - $row[$rowcount] = PMA_mysql_fetch_array($result[$rowcount]); + $result[$rowcount] = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($table) . ' WHERE ' . $primary_key . ';'); + $row[$rowcount] = PMA_DBI_fetch_assoc($result[$rowcount]); $primary_keys[$rowcount] = $primary_key; - + // No row returned if (!$row[$rowcount]) { unset($row[$rowcount]); @@ -119,8 +118,7 @@ if (isset($primary_key)) { } // end if (no record returned) } } else { - $local_query = 'SELECT * FROM ' . PMA_backquote($table) . ' LIMIT 1'; - $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url); + $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($table) . ' LIMIT 1;'); unset($row); } @@ -200,7 +198,7 @@ $fields_cnt = PMA_DBI_num_rows($table_def); $insert_mode = (!isset($row) ? TRUE : FALSE); $loop_array = (isset($row) ? $row : array(0 => FALSE)); -while ($trow = PMA_mysql_fetch_array($table_def)) { +while ($trow = PMA_DBI_fetch_assoc($table_def)) { $trow_table_def[] = $trow; } @@ -240,12 +238,12 @@ foreach($loop_array AS $vrowcount => $vrow) { // Sets a multiplier used for input-field counts (as zero cannot be used, advance the counter plus one) $m_rows = $o_rows + 1; - + for ($i = 0; $i < $fields_cnt; $i++) { // Display the submit button after every 15 lines --swix // (wanted to use an <a href="#bottom"> and <a name> instead, // but it didn't worked because of the <base href>) - + if ((($i % 15) == 0) && ($i != 0)) { ?> <tr> @@ -256,12 +254,12 @@ foreach($loop_array AS $vrowcount => $vrow) { <?php } // end if echo "\n"; - + $row_table_def = $trow_table_def[$i]; $row_table_def['True_Type'] = preg_replace('@\(.*@s', '', $row_table_def['Type']); - + $field = $row_table_def['Field']; - + // garvin: possible workaround. If current field is numerical, do not try to // access the result-array with its 'associative' key but with its numerical // represantation. @@ -270,7 +268,7 @@ foreach($loop_array AS $vrowcount => $vrow) { } else { $rowfield = $field; } - + // d a t e t i m e // // loic1: current date should not be set as default if the field is NULL @@ -295,16 +293,16 @@ foreach($loop_array AS $vrowcount => $vrow) { } $len = (preg_match('@float|double@', $row_table_def['Type'])) ? 100 - : @mysql_field_len($vresult, $i); + : @mysql_field_len($vresult, $i); // !UNWRAPPED FUNCTION! $first_timestamp = 0; - + $bgcolor = ($i % 2) ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']; ?> <tr> <td <?php echo ($cfg['LongtextDoubleTextarea'] && strstr($row_table_def['True_Type'], 'longtext') ? 'rowspan="2"' : ''); ?> align="center" bgcolor="<?php echo $bgcolor; ?>"><?php echo htmlspecialchars($field); ?></td> <?php echo "\n"; - + // The type column $is_binary = stristr($row_table_def['Type'], ' binary'); $is_blob = stristr($row_table_def['Type'], 'blob'); @@ -326,7 +324,7 @@ foreach($loop_array AS $vrowcount => $vrow) { $type = $row_table_def['Type']; $type_nowrap = ' nowrap="nowrap"'; break; - + default: $type = $row_table_def['Type']; $type_nowrap = ' nowrap="nowrap"'; @@ -338,7 +336,7 @@ foreach($loop_array AS $vrowcount => $vrow) { </td> <?php echo "\n"; - + // Prepares the field value $real_null_value = FALSE; if (isset($vrow)) { @@ -378,7 +376,7 @@ foreach($loop_array AS $vrowcount => $vrow) { $special_chars = htmlspecialchars($row_table_def['Default']); $backup_field = ''; } - + // The function column // ------------------- // Change by Bernard M. Piller <bernard@bmpsystems.com> @@ -400,7 +398,7 @@ foreach($loop_array AS $vrowcount => $vrow) { <?php echo "\n"; $selected = ''; - + // garvin: Find the current type in the RestrictColumnTypes. Will result in 'FUNC_CHAR' // or something similar. Then directly look up the entry in the RestrictFunctions array, // which will then reveal the available dropdown options @@ -411,10 +409,10 @@ foreach($loop_array AS $vrowcount => $vrow) { } else { $dropdown = array(); } - + $dropdown_built = array(); $op_spacing_needed = FALSE; - + // garvin: loop on the dropdown array and print all available options for that field. $cnt_dropdown = count($dropdown); for ($j = 0; $j < $cnt_dropdown; $j++) { @@ -428,7 +426,7 @@ foreach($loop_array AS $vrowcount => $vrow) { $dropdown_built[$dropdown[$j]] = 'TRUE'; $op_spacing_needed = TRUE; } - + // garvin: For compatibility's sake, do not let out all other functions. Instead // print a seperator (blank) and then show ALL functions which weren't shown // yet. @@ -445,7 +443,7 @@ foreach($loop_array AS $vrowcount => $vrow) { echo '<option value="">--------</option>' . "\n"; $op_spacing_needed = FALSE; } - + echo ' '; echo '<option' . $selected . '>' . $cfg['Functions'][$j] . '</option>' . "\n"; } @@ -458,7 +456,7 @@ foreach($loop_array AS $vrowcount => $vrow) { } } // end if ($cfg['ShowFunctionFields']) echo "\n"; - + // The null column // --------------- echo ' <td bgcolor="' . $bgcolor . '">' . "\n"; @@ -491,12 +489,12 @@ foreach($loop_array AS $vrowcount => $vrow) { echo ' ' . "\n"; } echo ' </td>' . "\n"; - + // The value column (depends on type) // ---------------- - + require('./libraries/get_foreign.lib.php'); - + if (isset($foreign_link) && $foreign_link == true) { ?> <td bgcolor="<?php echo $bgcolor; ?>"> @@ -556,7 +554,7 @@ foreach($loop_array AS $vrowcount => $vrow) { <input type="hidden" name="fields<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" value="" /> <?php echo "\n" . ' ' . $backup_field; - + // show dropdown or radio depend on length if (strlen($row_table_def['Type']) > 20) { echo "\n"; @@ -565,7 +563,7 @@ foreach($loop_array AS $vrowcount => $vrow) { <option value=""></option> <?php echo "\n"; - + for ($j = 0; $j < $enum_cnt; $j++) { // Removes automatic MySQL escape format $enum_atom = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $enum[$j])); @@ -578,7 +576,7 @@ foreach($loop_array AS $vrowcount => $vrow) { } echo '>' . htmlspecialchars($enum_atom) . '</option>' . "\n"; } // end for - + ?> </select> <?php @@ -598,7 +596,7 @@ foreach($loop_array AS $vrowcount => $vrow) { echo 'tabindex="' . (($i * $m_rows) + 1) . '" />' . "\n"; echo ' <label for="field_' . ($i * $m_rows) . '_3_' . $j . '">' . htmlspecialchars($enum_atom) . '</label>' . "\n"; } // end for - + } // end else echo "\n"; ?> @@ -608,7 +606,7 @@ foreach($loop_array AS $vrowcount => $vrow) { } else if ($type == 'set') { $set = PMA_getEnumSetOptions($row_table_def['Type']); - + if (isset($vset)) { unset($vset); } @@ -666,7 +664,7 @@ foreach($loop_array AS $vrowcount => $vrow) { <textarea name="fields<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" rows="<?php echo $cfg['TextareaRows']; ?>" cols="<?php echo $cfg['TextareaCols']; ?>" wrap="virtual" dir="<?php echo $text_dir; ?>" id="field_<?php echo ($i*$m_rows); ?>_3" <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>', '<?php echo $vkey; ?>')" tabindex="<?php echo (($i * $m_rows) + 1); ?>" ><?php echo $special_chars; ?></textarea> <?php - + } else { if ($len < 4) { $fieldsize = $maxlength = 4; @@ -681,11 +679,11 @@ foreach($loop_array AS $vrowcount => $vrow) { <input type="text" name="fields<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>" maxlength="<?php echo $maxlength; ?>" class="textfield" <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>', '<?php echo $vkey; ?>')" tabindex="<?php echo (($i * $m_rows) + 1); ?>" id="field_<?php echo ($i * $m_rows); ?>_3" /> <?php } // end if...elseif...else - + // Upload choice (only for BLOBs because the binary // attribute does not imply binary contents) // (displayed whatever value the ProtectBinary has) - + if ($is_upload && $is_blob) { echo '<input type="file" name="fields_upload_' . urlencode($field) . $vkey . '" class="textfield" id="field_' . ($i * $m_rows) . '_3" size="10" /> '; @@ -701,9 +699,9 @@ foreach($loop_array AS $vrowcount => $vrow) { $this_field_max_size = $max_field_sizes[$type]; } echo PMA_displayMaximumUploadSize($this_field_max_size) . "\n"; - echo ' ' . PMA_generateHiddenMaxFileSize($this_field_max_size) . "\n"; + echo ' ' . PMA_generateHiddenMaxFileSize($this_field_max_size) . "\n"; } - + if (!empty($cfg['UploadDir'])) { if (substr($cfg['UploadDir'], -1) != '/') { $cfg['UploadDir'] .= '/'; @@ -731,9 +729,9 @@ foreach($loop_array AS $vrowcount => $vrow) { echo ' ' . $strWebServerUploadDirectoryError . "\n"; } } // end if (web-server upload directory) - + echo '</td>'; - + } // end else if ( binary or blob) else { // For char or varchar, respect the maximum length (M); for other diff --git a/tbl_create.php b/tbl_create.php index 05077d666a..b29798728a 100644 --- a/tbl_create.php +++ b/tbl_create.php @@ -25,13 +25,13 @@ $err_url = 'tbl_properties.php?' . PMA_generate_common_url($db, $table); /** * Selects the database to work with */ -PMA_mysql_select_db($db); +PMA_DBI_select_db($db); /** * The form used to define the structure of the table has been submitted */ -$abort = false; +$abort = FALSE; if (isset($submit)) { $sql_query = $query_cpy = ''; @@ -174,10 +174,10 @@ if (isset($submit)) { } // Executes the query - $error_create = false; - $result = PMA_mysql_query($sql_query) or $error_create = true; + $error_create = FALSE; + $result = PMA_DBI_try_query($sql_query) or $error_create = TRUE; - if ($error_create == false) { + if ($error_create == FALSE) { $sql_query = $query_cpy . ';'; unset($query_cpy); $message = $strTable . ' ' . htmlspecialchars($table) . ' ' . $strHasBeenCreated; @@ -211,7 +211,7 @@ if (isset($submit)) { // to prevent total loss of that data, we embed the form once again. // The variable $regenerate will be used to restore data in tbl_properties.inc.php $num_fields = $orig_num_fields; - $regenerate = true; + $regenerate = TRUE; } } // end do create table diff --git a/tbl_indexes.php b/tbl_indexes.php index c544f9acd7..cab4dcf95a 100644 --- a/tbl_indexes.php +++ b/tbl_indexes.php @@ -29,7 +29,7 @@ $index_types = array( if (!defined('PMA_IDX_INCLUDED')) { // Not a valid db name -> back to the welcome page if (!empty($db)) { - $is_db = @PMA_mysql_select_db($db); + $is_db = PMA_DBI_select_db($db); } if (empty($db) || !$is_db) { header('Location: ' . $cfg['PmaAbsoluteUri'] . 'main.php?' . PMA_generate_common_url('', '', '&') . (isset($message) ? '&message=' . urlencode($message) : '') . '&reload=1'); @@ -37,10 +37,10 @@ if (!defined('PMA_IDX_INCLUDED')) { } // Not a valid table name -> back to the default db_details sub-page if (!empty($table)) { - $is_table = @PMA_mysql_query('SHOW TABLES LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\''); + $is_table = PMA_DBI_query('SHOW TABLES LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\''); } if (empty($table) - || !($is_table && @PMA_DBI_num_rows($is_table))) { + || !($is_table && PMA_DBI_num_rows($is_table))) { header('Location: ' . $cfg['PmaAbsoluteUri'] . $cfg['DefaultTabDatabase'] . '?' . PMA_generate_common_url($db, '', '&') . (isset($message) ? '&message=' . urlencode($message) : '') . '&reload=1'); exit; } else if (isset($is_table)) { @@ -70,12 +70,12 @@ if (defined('PMA_IDX_INCLUDED')) { $idx_cnt = count($ret_keys); } else { $local_query = 'SHOW KEYS FROM ' . PMA_backquote($table); - $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url_0); + $result = PMA_DBI_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url_0); $idx_cnt = PMA_DBI_num_rows($result); } for ($i = 0; $i < $idx_cnt; $i++) { - $row = (defined('PMA_IDX_INCLUDED') ? $ret_keys[$i] : PMA_mysql_fetch_array($result)); + $row = (defined('PMA_IDX_INCLUDED') ? $ret_keys[$i] : PMA_DBI_fetch_assoc($result)); if ($row['Key_name'] != $prev_index ){ $indexes[] = $row['Key_name']; @@ -110,16 +110,15 @@ if (defined('PMA_IDX_INCLUDED')) { // Get fields and stores their name/type // fields had already been grabbed in "tbl_properties.php" if (defined('PMA_IDX_INCLUDED')) { - mysql_data_seek($fields_rs, 0); + mysql_data_seek($fields_rs, 0); // !UNWRAPPED FUNCTION! } else { - $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table); - $fields_rs = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url_0); + $fields_rs = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';'); $fields_cnt = PMA_DBI_num_rows($fields_rs); } $fields_names = array(); $fields_types = array(); -while ($row = PMA_mysql_fetch_array($fields_rs)) { +while ($row = PMA_DBI_fetch_assoc($fields_rs)) { $fields_names[] = $row['Field']; // loic1: set or enum types: slashes single quotes inside options if (preg_match('@^(set|enum)\((.+)\)$@i', $row['Type'], $tmp)) { @@ -201,7 +200,7 @@ if (!defined('PMA_IDX_INCLUDED') $sql_query .= $index_fields . ')'; } - $result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', $sql_query, FALSE, $err_url); + $result = PMA_DBI_query($sql_query); $message = $strTable . ' ' . htmlspecialchars($table) . ' ' . $strHasBeenAltered; $active_page = 'tbl_properties_structure.php'; diff --git a/tbl_move_copy.php b/tbl_move_copy.php index b71ced8290..cfb64a38ae 100644 --- a/tbl_move_copy.php +++ b/tbl_move_copy.php @@ -25,10 +25,10 @@ function PMA_myHandler($sql_insert = '') global $sql_insert_data; $sql_insert = preg_replace('~INSERT INTO (`?)' . $table . '(`?)~i', 'INSERT INTO ' . $target, $sql_insert); - $result = PMA_mysql_query($sql_insert) or PMA_mysqlDie('', $sql_insert, '', $GLOBALS['err_url']); + $result = PMA_DBI_query($sql_insert); $sql_insert_data .= $sql_insert . ';' . "\n"; -} // end of the 'PMA_myHandler()' function +} // end of the 'PMA_myHandler()' function /** * Inserts existing entries in a PMA_* table by reading a value from an old entry @@ -78,7 +78,7 @@ global $cfgRelation; . ' WHERE ' . implode(' AND ', $where_parts); $table_copy_rs = PMA_query_as_cu($table_copy_query); - while ($table_copy_row = @PMA_mysql_fetch_array($table_copy_rs)) { + while ($table_copy_row = @PMA_DBI_fetch_assoc($table_copy_rs)) { $value_parts = array(); foreach($table_copy_row AS $_key => $_val) { if (isset($row_fields[$_key]) && $row_fields[$_key] == 'cc') { @@ -92,7 +92,7 @@ global $cfgRelation; . ' (\'' . implode('\', \'', $value_parts) . '\', \'' . implode('\', \'', $new_value_parts) . '\')'; $new_table_rs = PMA_query_as_cu($new_table_query); - $last_id = (@function_exists('mysql_insert_id') ? @PMA_DBI_insert_id() : -1); + $last_id = PMA_DBI_insert_id(); } // end while return $last_id; @@ -117,7 +117,7 @@ $err_url = 'tbl_properties.php?' . PMA_generate_common_url($db, $table); /** * Selects the database to work with */ -PMA_mysql_select_db($db); +PMA_DBI_select_db($db); /** @@ -141,7 +141,7 @@ if (isset($new_name) && trim($new_name) != '') { // This could avoid some problems with replicated databases, when // moving table from replicated one to not replicated one - PMA_mysql_select_db($target_db); + PMA_DBI_select_db($target_db); $target = PMA_backquote($target_db) . '.' . PMA_backquote($new_name); @@ -169,11 +169,7 @@ if (isset($new_name) && trim($new_name) != '') { $drop_query = ''; if (isset($drop_if_exists) && $drop_if_exists == 'true') { $drop_query = 'DROP TABLE IF EXISTS ' . PMA_backquote($target_db) . '.' . PMA_backquote($new_name); - $result = @PMA_mysql_query($drop_query); - if (PMA_mysql_error()) { - require_once('./header.inc.php'); - PMA_mysqlDie('', $sql_structure, '', $err_url); - } + $result = PMA_DBI_query($drop_query); if (isset($sql_query)) { $sql_query .= "\n" . $drop_query . ';'; @@ -183,14 +179,11 @@ if (isset($new_name) && trim($new_name) != '') { // garvin: If an existing table gets deleted, maintain any entries // for the PMA_* tables - $maintain_relations = true; + $maintain_relations = TRUE; } - $result = @PMA_mysql_query($sql_structure); - if (PMA_mysql_error()) { - require_once('./header.inc.php'); - PMA_mysqlDie('', $sql_structure, '', $err_url); - } else if (isset($sql_query)) { + $result = @PMA_DBI_query($sql_structure); + if (isset($sql_query)) { $sql_query .= "\n" . $sql_structure . ';'; } else { $sql_query = $sql_structure . ';'; @@ -207,11 +200,8 @@ if (isset($new_name) && trim($new_name) != '') { /* Generate query back */ $sql_constraints = PMA_SQP_formatHtml($parsed_sql, 'query_only'); - $result = @PMA_mysql_query($sql_constraints); - if (PMA_mysql_error()) { - require_once('./header.inc.php'); - PMA_mysqlDie('', $sql_structure, '', $err_url); - } else if (isset($sql_query)) { + $result = PMA_DBI_query($sql_constraints); + if (isset($sql_query)) { $sql_query .= "\n" . $sql_constraints; } else { $sql_query = $sql_constraints; @@ -225,12 +215,8 @@ if (isset($new_name) && trim($new_name) != '') { // Copy the data if ($result != FALSE && ($what == 'data' || $what == 'dataonly')) { $sql_insert_data = 'INSERT INTO ' . $target . ' SELECT * FROM ' . $source; - $result = @PMA_mysql_query($sql_insert_data); - if (PMA_mysql_error()) { - require_once('./header.inc.php'); - PMA_mysqlDie('', $sql_insert_data, '', $err_url); - } - $sql_query .= "\n\n" . $sql_insert_data . ';'; + PMA_DBI_query($sql_insert_data); + $sql_query .= "\n\n" . $sql_insert_data . ';'; } require_once('./libraries/relation.lib.php'); @@ -241,14 +227,10 @@ if (isset($new_name) && trim($new_name) != '') { // This could avoid some problems with replicated databases, when // moving table from replicated one to not replicated one - PMA_mysql_select_db($db); + PMA_DBI_select_db($db); $sql_drop_table = 'DROP TABLE ' . $source; - $result = @PMA_mysql_query($sql_drop_table); - if (PMA_mysql_error()) { - require_once('./header.inc.php'); - PMA_mysqlDie('', $sql_drop_table, '', $err_url); - } + PMA_DBI_query($sql_drop_table); // garvin: Move old entries from PMA-DBs to new table if ($cfgRelation['commwork']) { @@ -323,7 +305,7 @@ if (isset($new_name) && trim($new_name) != '') { . ' AND table_name = \'' . PMA_sqlAddslashes($new_name) . '\''; $pdf_rs = PMA_query_as_cu($pdf_query); - while ($pdf_copy_row = @PMA_mysql_fetch_array($pdf_rs)) { + while ($pdf_copy_row = PMA_DBI_fetch_assoc($pdf_rs)) { $table_query = 'UPDATE ' . PMA_backquote($cfgRelation['pdf_pages']) . ' SET db_name = \'' . PMA_sqlAddslashes($target_db) . '\'' . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' @@ -350,7 +332,7 @@ if (isset($new_name) && trim($new_name) != '') { $comments_copy_rs = PMA_query_as_cu($comments_copy_query); // Write every comment as new copied entry. [MIME] - while ($comments_copy_row = @PMA_mysql_fetch_array($comments_copy_rs)) { + while ($comments_copy_row = PMA_DBI_fetch_assoc($comments_copy_rs)) { $new_comment_query = 'REPLACE INTO ' . PMA_backquote($cfgRelation['column_info']) . ' (db_name, table_name, column_name, ' . PMA_backquote('comment') . ($cfgRelation['mimework'] ? ', mimetype, transformation, transformation_options' : '') . ') ' . ' VALUES(' diff --git a/tbl_printview.php b/tbl_printview.php index e9684c3a18..9ddac745c7 100644 --- a/tbl_printview.php +++ b/tbl_printview.php @@ -38,7 +38,7 @@ if (isset($table)) { /** * Selects the database */ -PMA_mysql_select_db($db); +PMA_DBI_select_db($db); /** @@ -79,21 +79,17 @@ foreach($the_tables AS $key => $table) { /** * Gets table informations */ - $local_query = 'SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\''; - $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url); - $showtable = PMA_mysql_fetch_array($result); + $result = PMA_DBI_query('SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\';'); + $showtable = PMA_DBI_fetch_assoc($result); $num_rows = (isset($showtable['Rows']) ? $showtable['Rows'] : 0); $show_comment = (isset($showtable['Comment']) ? $showtable['Comment'] : ''); - if ($result) { - PMA_DBI_free_result($result); - } + PMA_DBI_free_result($result); /** * Gets table keys and retains them */ - $local_query = 'SHOW KEYS FROM ' . PMA_backquote($table); - $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url); + $result = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';'); $primary = ''; $indexes = array(); $lastIndex = ''; @@ -101,7 +97,7 @@ foreach($the_tables AS $key => $table) { $indexes_data = array(); $pk_array = array(); // will be use to emphasis prim. keys in the table // view - while ($row = PMA_mysql_fetch_array($result)) { + while ($row = PMA_DBI_fetch_assoc($result)) { // Backups the list of primary keys if ($row['Key_name'] == 'PRIMARY') { $primary .= $row['Column_name'] . ', '; @@ -135,8 +131,7 @@ foreach($the_tables AS $key => $table) { /** * Gets fields properties */ - $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table); - $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url); + $result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';'); $fields_cnt = PMA_DBI_num_rows($result); // Check if we can use Relations (Mike Beck) @@ -193,7 +188,7 @@ foreach($the_tables AS $key => $table) { <?php $i = 0; - while ($row = PMA_mysql_fetch_array($result)) { + while ($row = PMA_DBI_fetch_assoc($result)) { $bgcolor = ($i % 2) ?$cfg['BgcolorOne'] : $cfg['BgcolorTwo']; $i++; diff --git a/tbl_properties.inc.php b/tbl_properties.inc.php index 7458526b40..463bb8947c 100644 --- a/tbl_properties.inc.php +++ b/tbl_properties.inc.php @@ -558,10 +558,9 @@ if ($action == 'tbl_create.php') { // change by staybyte - 11 June 2001 if ($action == 'tbl_create.php') { // find mysql capability - staybyte - 11. June 2001 - $query = 'SHOW VARIABLES LIKE \'have_%\''; - $result = PMA_mysql_query($query); + $result = PMA_DBI_try_query('SHOW VARIABLES LIKE \'have_%\';'); if ($result != FALSE && PMA_DBI_num_rows($result) > 0) { - while ($tmp = PMA_mysql_fetch_array($result)) { + while ($tmp = PMA_DBI_fetch_assoc($result)) { if (isset($tmp['Variable_name'])) { switch ($tmp['Variable_name']) { case 'have_bdb': diff --git a/tbl_properties_operations.php b/tbl_properties_operations.php index 5b3d831a3f..dd7feb1ef1 100644 --- a/tbl_properties_operations.php +++ b/tbl_properties_operations.php @@ -28,18 +28,18 @@ require_once('./libraries/mysql_charsets.lib.php'); if (isset($submitcomment)) { if (empty($prev_comment) || urldecode($prev_comment) != $comment) { $sql_query = 'ALTER TABLE ' . PMA_backquote($table) . ' COMMENT = \'' . PMA_sqlAddslashes($comment) . '\''; - $result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', $sql_query, '', $err_url); + $result = PMA_DBI_query($sql_query); $message = $strSuccess; } } if (isset($submittype)) { $sql_query = 'ALTER TABLE ' . PMA_backquote($table) . ' TYPE = ' . $tbl_type; - $result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', $sql_query, '', $err_url); + $result = PMA_DBI_query($sql_query); $message = $strSuccess; } if (isset($submitcharset)) { $sql_query = 'ALTER TABLE ' . PMA_backquote($table) . ' DEFAULT CHARACTER SET = ' . $tbl_charset; - $result = PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query, '', $err_url); + $result = PMA_DBI_query($sql_query); $message = $strSuccess; } if (isset($submitoptions)) { @@ -48,7 +48,7 @@ if (isset($submitoptions)) { . (isset($checksum) ? ' checksum=1': ' checksum=0') . (isset($delay_key_write) ? ' delay_key_write=1': ' delay_key_write=0') . (isset($auto_increment) ? ' auto_increment=' . PMA_sqlAddslashes($auto_increment) : ''); - $result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', $sql_query, '', $err_url); + $result = PMA_DBI_query($sql_query); $message = $strSuccess; } @@ -65,7 +65,7 @@ if (isset($message)) { if (isset($submitorderby) && !empty($order_field)) { $sql_query = 'ALTER TABLE ' . PMA_backquote($table) . ' ORDER BY ' . PMA_backquote(urldecode($order_field)); - $result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', $sql_query, '', $err_url); + $result = PMA_DBI_query($sql_query); PMA_showMessage($strSuccess); } // end if @@ -80,11 +80,12 @@ require('./tbl_properties_table_info.php'); * Get columns names */ $local_query = 'SHOW COLUMNS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db); -$result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $error_url); -for ($i = 0; $row = PMA_mysql_fetch_array($result); $i++) { +$result = PMA_DBI_query($local_query); +for ($i = 0; $row = PMA_DBI_fetch_assoc($result); $i++) { $columns[$i] = $row['Field']; } PMA_DBI_free_result($result); +unset($result); /** @@ -296,10 +297,10 @@ echo "\n"; if ($cfgRelation['relwork'] && $tbl_type != "INNODB") { - // we need this PMA_mysql_select_db if the user has access to more than one db + // we need this PMA_DBI_select_db if the user has access to more than one db // and $db is not the last of the list, because PMA_availableDatabases() - // has made a PMA_mysql_select_db() on the last one - PMA_mysql_select_db($db); + // has made a PMA_DBI_select_db() on the last one + PMA_DBI_select_db($db); $foreign = PMA_getForeigners($db, $table); if ($foreign) { @@ -369,10 +370,9 @@ if ($cfgRelation['relwork'] && $tbl_type != "INNODB") { <!-- Table type --> <?php // modify robbat2 code - staybyte - 11. June 2001 - $query = 'SHOW VARIABLES LIKE \'have_%\''; - $result = PMA_mysql_query($query); + $result = PMA_DBI_query('SHOW VARIABLES LIKE \'have_%\';'); if ($result != FALSE && PMA_DBI_num_rows($result) > 0) { - while ($tmp = PMA_mysql_fetch_array($result)) { + while ($tmp = PMA_DBI_fetch_assoc($result)) { if (isset($tmp['Variable_name'])) { switch ($tmp['Variable_name']) { case 'have_bdb': diff --git a/tbl_properties_structure.php b/tbl_properties_structure.php index 3172727d89..7dff576119 100644 --- a/tbl_properties_structure.php +++ b/tbl_properties_structure.php @@ -46,12 +46,11 @@ if ((!empty($submit_mult) && isset($selected_fld)) } // 2. Gets table keys and retains them -$local_query = 'SHOW KEYS FROM ' . PMA_backquote($table); -$result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url_0); +$result = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';'); $primary = ''; $ret_keys = array(); $pk_array = array(); // will be use to emphasis prim. keys in the table view -while ($row = PMA_mysql_fetch_array($result)) { +while ($row = PMA_DBI_fetch_assoc($result)) { $ret_keys[] = $row; // Backups the list of primary keys if ($row['Key_name'] == 'PRIMARY') { @@ -62,8 +61,7 @@ while ($row = PMA_mysql_fetch_array($result)) { PMA_DBI_free_result($result); // 3. Get fields -$local_query = 'SHOW FULL FIELDS FROM ' . PMA_backquote($table); -$fields_rs = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url_0); +$fields_rs = PMA_DBI_query('SHOW FULL FIELDS FROM ' . PMA_backquote($table) . ';'); $fields_cnt = PMA_DBI_num_rows($fields_rs); @@ -115,7 +113,7 @@ $i = 0; $aryFields = array(); $checked = (!empty($checkall) ? ' checked="checked"' : ''); -while ($row = PMA_mysql_fetch_array($fields_rs)) { +while ($row = PMA_DBI_fetch_assoc($fields_rs)) { $i++; $bgcolor = ($i % 2) ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']; $aryFields[] = $row['Field']; diff --git a/tbl_properties_table_info.php b/tbl_properties_table_info.php index d589aeaeb0..5cc062e3fb 100644 --- a/tbl_properties_table_info.php +++ b/tbl_properties_table_info.php @@ -15,9 +15,8 @@ PMA_checkParameters(array('db', 'table')); * Gets table informations */ // The 'show table' statement works correct since 3.23.03 -$local_query = 'SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\''; -$table_info_result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url_0); -$showtable = PMA_mysql_fetch_array($table_info_result); +$table_info_result = PMA_DBI_query('SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\';'); +$showtable = PMA_DBI_fetch_assoc($table_info_result); $tbl_type = strtoupper($showtable['Type']); $tbl_charset = empty($showtable['Collation']) ? '' : $showtable['Collation']; $table_info_num_rows = (isset($showtable['Rows']) ? $showtable['Rows'] : 0); diff --git a/tbl_query_box.php b/tbl_query_box.php index e132ad571f..35826b9e58 100644 --- a/tbl_query_box.php +++ b/tbl_query_box.php @@ -33,18 +33,12 @@ unset($sql_query); */ $fields_cnt = 0; if (isset($db) && isset($table) && $table != '' && $db != '') { - $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db); - $result = @PMA_mysql_query($local_query); - if (!$result) { - PMA_mysqlDie('', $local_query, '', $err_url); - } - else { - $fields_cnt = PMA_DBI_num_rows($result); - while ($row = PMA_mysql_fetch_array($result)) { - $fields_list[] = $row['Field']; - } // end while - PMA_DBI_free_result($result); - } + $result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db) . ';'); + $fields_cnt = PMA_DBI_num_rows($result); + while ($row = PMA_DBI_fetch_assoc($result)) { + $fields_list[] = $row['Field']; + } // end while + PMA_DBI_free_result($result); } /** diff --git a/tbl_relation.php b/tbl_relation.php index 02c6a58529..84b4b6c22a 100644 --- a/tbl_relation.php +++ b/tbl_relation.php @@ -156,7 +156,7 @@ if ($cfgRelation['relwork'] . PMA_backquote($existrel_innodb[$master_field]['constraint']); // I tried to send both in one query but it failed - $upd_rs = PMA_mysql_query($upd_query); + $upd_rs = PMA_DBI_query($upd_query); } // add another @@ -185,8 +185,8 @@ if ($cfgRelation['relwork'] } // end if... else.... if (isset($upd_query)) { - $upd_rs = PMA_mysql_query($upd_query); - if (PMA_mysql_error() && mysql_errno() == 1005) { + $upd_rs = PMA_DBI_query($upd_query); + if (substr(PMA_DBI_getError(), 1, 4) == '1005') { echo '<p class="warning">' . $strNoIndex . ' (' . $master_field .')</p>' . PMA_showMySQLDocu('manual_Table_types', 'InnoDB_foreign_key_constraints') . "\n"; } unset($upd_query); @@ -269,19 +269,18 @@ if ($cfgRelation['relwork']) { } // [0] of the row is the name - $tab_rs = PMA_mysql_query($tab_query) or PMA_mysqlDie('', $tab_query, '', $err_url_0); + $tab_rs = PMA_DBI_query($tab_query); $selectboxall['nix'] = '--'; $selectboxall_innodb['nix'] = '--'; - while ($curr_table = @PMA_mysql_fetch_array($tab_rs)) { + while ($curr_table = @PMA_DBI_fetch_row($tab_rs)) { if (($curr_table[0] != $table) && ($curr_table[0] != $cfg['Server']['relation'])) { - $fi_query = 'SHOW KEYS FROM ' . PMA_backquote($curr_table[0]); - $fi_rs = PMA_mysql_query($fi_query) or PMA_mysqlDie('', $fi_query, '', $err_url_0); + $fi_rs = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($curr_table[0]) . ';'); if ($fi_rs && PMA_DBI_num_rows($fi_rs) > 0) { - $seen_a_primary=FALSE; - while ($curr_field = PMA_mysql_fetch_array($fi_rs)) { + $seen_a_primary = FALSE; + while ($curr_field = PMA_DBI_fetch_assoc($fi_rs)) { if (isset($curr_field['Key_name']) && $curr_field['Key_name'] == 'PRIMARY') { - $seen_a_primary=TRUE; + $seen_a_primary = TRUE; $field_full = $db . '.' .$curr_field['Table'] . '.' . $curr_field['Column_name']; $field_v = $curr_field['Table'] . '->' . $curr_field['Column_name']; $selectboxall[$field_full] = $field_v; @@ -320,10 +319,9 @@ if ($cfgRelation['relwork']) { // current table (see bug report #574851) } else if ($curr_table[0] == $table) { - $fi_query = 'SHOW KEYS FROM ' . PMA_backquote($curr_table[0]); - $fi_rs = PMA_mysql_query($fi_query) or PMA_mysqlDie('', $fi_query, '', $err_url_0); + $fi_rs = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($curr_table[0]) . ';'); if ($fi_rs && PMA_DBI_num_rows($fi_rs) > 0) { - while ($curr_field = PMA_mysql_fetch_array($fi_rs)) { + while ($curr_field = PMA_DBI_fetch_assoc($fi_rs)) { $field_full = $db . '.' . $curr_field['Table'] . '.' . $curr_field['Column_name']; $field_v = $curr_field['Table'] . '->' . $curr_field['Column_name']; $selectboxall[$field_full] = $field_v; @@ -339,11 +337,10 @@ if ($cfgRelation['relwork']) { // Now find out the columns of our $table -$col_query = 'SHOW COLUMNS FROM ' . PMA_backquote($table); -$col_rs = PMA_mysql_query($col_query) or PMA_mysqlDie('', $col_query, '', $err_url_0); +$col_rs = PMA_mysql_query('SHOW COLUMNS FROM ' . PMA_backquote($table) . ';'); if ($col_rs && PMA_DBI_num_rows($col_rs) > 0) { - while ($row = PMA_mysql_fetch_array($col_rs)) { + while ($row = PMA_DBI_fetch_assoc($col_rs)) { $save_row[] = $row; } $saved_row_cnt = count($save_row); @@ -508,8 +505,8 @@ if ($col_rs && PMA_DBI_num_rows($col_rs) > 0) { <option value="">---</option> <?php echo "\n"; - mysql_data_seek($col_rs, 0); - while ($row = @PMA_mysql_fetch_array($col_rs)) { + mysql_data_seek($col_rs, 0); // !UNWRAPPED FUNCTION! + while ($row = @PMA_DBI_fetch_array($col_rs)) { echo ' <option value="' . htmlspecialchars($row['Field']) . '"'; if (isset($disp) && $row['Field'] == $disp) { echo ' selected="selected"'; diff --git a/tbl_rename.php b/tbl_rename.php index 070df4fe04..607dd194dd 100644 --- a/tbl_rename.php +++ b/tbl_rename.php @@ -31,9 +31,9 @@ if (isset($new_name) && trim($new_name) != '' && strpos($new_name,'.') === FALSE } require_once('./header.inc.php'); - PMA_mysql_select_db($db); - $sql_query = 'ALTER TABLE ' . PMA_backquote($old_name) . ' RENAME ' . PMA_backquote($new_name); - $result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', '', '', $err_url); + PMA_DBI_select_db($db); + $sql_query = 'ALTER TABLE ' . PMA_backquote($old_name) . ' RENAME ' . PMA_backquote($new_name) . ';'; + $result = PMA_DBI_query($sql_query); $message = sprintf($strRenameTableOK, htmlspecialchars($old_name), htmlspecialchars($table)); $reload = 1; diff --git a/tbl_replace.php b/tbl_replace.php index fe93eae974..1ce8ef876b 100644 --- a/tbl_replace.php +++ b/tbl_replace.php @@ -74,30 +74,30 @@ $seen_binary = FALSE; */ if (isset($primary_key) && ($submit_type != $strInsertAsNewRow)) { $loop_array = (is_array($primary_key) ? $primary_key : array(0 => $primary_key)); - PMA_mysql_select_db($db); + PMA_DBI_select_db($db); $query = array(); $message = ''; - + foreach($loop_array AS $primary_key_index => $enc_primary_key) { // Restore the "primary key" to a convenient format $primary_key = urldecode($enc_primary_key); - + // Defines the SET part of the sql query $valuelist = ''; - + // Map multi-edit keys to single-level arrays, dependent on how we got the fields $me_fields = (isset($fields['multi_edit']) && isset($fields['multi_edit'][$enc_primary_key]) ? $fields['multi_edit'][$enc_primary_key] : (isset($fields) ? $fields : null)); $me_fields_prev = (isset($fields_prev['multi_edit']) && isset($fields_prev['multi_edit'][$enc_primary_key]) ? $fields_prev['multi_edit'][$enc_primary_key] : (isset($fields_prev) ? $fields_prev : null)); $me_funcs = (isset($funcs['multi_edit']) && isset($funcs['multi_edit'][$enc_primary_key]) ? $funcs['multi_edit'][$enc_primary_key] : (isset($funcs) ? $funcs : null)); $me_fields_type = (isset($fields_type['multi_edit']) && isset($fields_type['multi_edit'][$enc_primary_key]) ? $fields_type['multi_edit'][$enc_primary_key] : (isset($fields_type) ? $fields_type : null)); $me_fields_null = (isset($fields_null['multi_edit']) && isset($fields_null['multi_edit'][$enc_primary_key]) ? $fields_null['multi_edit'][$enc_primary_key] : (isset($fields_null) ? $fields_null : null)); - + foreach($me_fields AS $key => $val) { $encoded_key = $key; $key = urldecode($key); - + require('./tbl_replace_fields.php'); - + // No change for this column and no MySQL function is used -> next column if (empty($me_funcs[$encoded_key]) && isset($me_fields_prev) && isset($me_fields_prev[$encoded_key]) @@ -115,7 +115,7 @@ if (isset($primary_key) && ($submit_type != $strInsertAsNewRow)) { } } } // end while - + // Builds the sql update query $valuelist = preg_replace('@, $@', '', $valuelist); if (!empty($valuelist)) { @@ -127,7 +127,7 @@ if (isset($primary_key) && ($submit_type != $strInsertAsNewRow)) { $message = $strAffectedRows . ' '; } } - + if (empty($valuelist)) { // No change -> move back to the calling script $message = $strNoModification; @@ -150,12 +150,12 @@ else { $loop_array = (isset($primary_key) && is_array($primary_key) ? $primary_key : array(0 => (isset($primary_key) ? $primary_key : null))); $query = array(); $message = ''; - PMA_mysql_select_db($db); - + PMA_DBI_select_db($db); + foreach($loop_array AS $primary_key_index => $enc_primary_key) { $fieldlist = ''; $valuelist = ''; - + $me_fields = (isset($fields['multi_edit']) && isset($fields['multi_edit'][$enc_primary_key]) ? $fields['multi_edit'][$enc_primary_key] : (isset($fields) ? $fields : null)); $me_fields_prev = (isset($fields_prev['multi_edit']) && isset($fields_prev['multi_edit'][$enc_primary_key]) ? $fields_prev['multi_edit'][$enc_primary_key] : (isset($fields_prev) ? $fields_prev : null)); $me_funcs = (isset($funcs['multi_edit']) && isset($funcs['multi_edit'][$enc_primary_key]) ? $funcs['multi_edit'][$enc_primary_key] : (isset($funcs) ? $funcs : null)); @@ -164,18 +164,17 @@ else { // garvin: Get, if sent, any protected fields to insert them here: if (isset($me_fields_type) && is_array($me_fields_type) && isset($enc_primary_key)) { - $prot_local_query = 'SELECT * FROM ' . PMA_backquote($table) . ' WHERE ' . urldecode($enc_primary_key); - $prot_result = PMA_mysql_query($prot_local_query) or PMA_mysqlDie('', $prot_local_query, '', $err_url); - $prot_row = PMA_mysql_fetch_array($prot_result); + $prot_result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($table) . ' WHERE ' . urldecode($enc_primary_key) . ';'); + $prot_row = PMA_DBI_fetch_assoc($prot_result); } - + foreach($me_fields AS $key => $val) { $encoded_key = $key; $key = urldecode($key); $fieldlist .= PMA_backquote($key) . ', '; - + require('./tbl_replace_fields.php'); - + if (empty($me_funcs[$encoded_key])) { $valuelist .= $val . ', '; } else if (($val == '\'\'' @@ -186,7 +185,7 @@ else { $valuelist .= $me_funcs[$encoded_key] . '(' . $val . '), '; } } // end while - + // Builds the sql insert query $fieldlist = preg_replace('@, $@', '', $fieldlist); $valuelist = preg_replace('@, $@', '', $valuelist); @@ -205,15 +204,13 @@ $total_affected_rows = 0; $last_message = ''; foreach($query AS $query_index => $single_query) { - $result = PMA_mysql_query($single_query); + if ($cfg['IgnoreMultiSubmitErrors']) { + $result = PMA_DBI_try_query($single_query); + } else { + $result = PMA_DBI_query($single_query); + } if (!$result) { - if ($cfg['IgnoreMultiSubmitErrors']) { - $message .= PMA_mysql_error(); - } else { - $error = PMA_mysql_error(); - require_once('./header.inc.php'); - PMA_mysqlDie($error, '', '', $err_url); - } + $message .= PMA_DBI_getError(); } else { if (@PMA_DBI_affected_rows()) { $total_affected_rows += @PMA_DBI_affected_rows(); diff --git a/tbl_select.php b/tbl_select.php index 675d157e9d..6068505c5a 100644 --- a/tbl_select.php +++ b/tbl_select.php @@ -55,40 +55,35 @@ if (!isset($param) || $param[0] == '') { $err_url = $goto . '?' . PMA_generate_common_url($db, $table); // Gets the list and number of fields - $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db); - $result = @PMA_mysql_query($local_query); - if (!$result) { - PMA_mysqlDie('', $local_query, '', $err_url); - } - else { - $fields_cnt = PMA_DBI_num_rows($result); - while ($row = PMA_mysql_fetch_array($result)) { - $fields_list[] = $row['Field']; - $type = $row['Type']; - // reformat mysql query output - staybyte - 9. June 2001 - $shorttype = substr($type, 0, 3); - if ($shorttype == 'set' || $shorttype == 'enu') { - $type = str_replace(',', ', ', $type); - } else { - $type = preg_replace('@BINARY@i', '', $type); - $type = preg_replace('@ZEROFILL@i', '', $type); - $type = preg_replace('@UNSIGNED@i', '', $type); - } - if (empty($type)) { - $type = ' '; - } - $fields_type[] = $type; - } // end while - PMA_DBI_free_result($result); + $result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db) . ';'); + $fields_cnt = PMA_DBI_num_rows($result); + while ($row = PMA_DBI_fetch_assoc($result)) { + $fields_list[] = $row['Field']; + $type = $row['Type']; + // reformat mysql query output - staybyte - 9. June 2001 + $shorttype = substr($type, 0, 3); + if ($shorttype == 'set' || $shorttype == 'enu') { + $type = str_replace(',', ', ', $type); + } else { + $type = preg_replace('@BINARY@i', '', $type); + $type = preg_replace('@ZEROFILL@i', '', $type); + $type = preg_replace('@UNSIGNED@i', '', $type); + } + if (empty($type)) { + $type = ' '; + } + $fields_type[] = $type; + } // end while + PMA_DBI_free_result($result); - // <markus@noga.de> - // retrieve keys into foreign fields, if any - $cfgRelation = PMA_getRelationsParam(); - // check also foreigners even if relwork is FALSE (to get - // foreign keys from innodb) - //$foreigners = ($cfgRelation['relwork'] ? PMA_getForeigners($db, $table) : FALSE); - $foreigners = PMA_getForeigners($db, $table); - ?> + // <markus@noga.de> + // retrieve keys into foreign fields, if any + $cfgRelation = PMA_getRelationsParam(); + // check also foreigners even if relwork is FALSE (to get + // foreign keys from innodb) + //$foreigners = ($cfgRelation['relwork'] ? PMA_getForeigners($db, $table) : FALSE); + $foreigners = PMA_getForeigners($db, $table); + ?> <form method="post" action="tbl_select.php" name="insertForm"> <?php echo PMA_generate_common_hidden_inputs($db, $table); ?> <input type="hidden" name="goto" value="<?php echo $goto; ?>" /> @@ -97,13 +92,13 @@ if (!isset($param) || $param[0] == '') { <?php echo $strSelectFields; ?> :<br /> <select name="param[]" size="<?php echo ($fields_cnt < 10) ? $fields_cnt : 10; ?>" multiple="multiple"> - <?php - echo "\n"; - // Displays the list of the fields - for ($i = 0 ; $i < $fields_cnt; $i++) { - echo ' <option value="' . htmlspecialchars($fields_list[$i]) . '" selected="selected">' . htmlspecialchars($fields_list[$i]) . '</option>' . "\n"; - } - ?> + <?php + echo "\n"; + // Displays the list of the fields + for ($i = 0 ; $i < $fields_cnt; $i++) { + echo ' <option value="' . htmlspecialchars($fields_list[$i]) . '" selected="selected">' . htmlspecialchars($fields_list[$i]) . '</option>' . "\n"; + } + ?> </select><br /> <ul> <li> @@ -125,95 +120,95 @@ if (!isset($param) || $param[0] == '') { <th><?php echo $strFunction; ?></th> <th><?php echo $strValue; ?></th> </tr> - <?php - for ($i = 0; $i < $fields_cnt; $i++) { - echo "\n"; - $bgcolor = ($i % 2) ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']; - ?> + <?php + for ($i = 0; $i < $fields_cnt; $i++) { + echo "\n"; + $bgcolor = ($i % 2) ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']; + ?> <tr> <td bgcolor="<?php echo $bgcolor; ?>"><?php echo htmlspecialchars($fields_list[$i]); ?></td> <td bgcolor="<?php echo $bgcolor; ?>"><?php echo $fields_type[$i]; ?></td> <td bgcolor="<?php echo $bgcolor; ?>"> <select name="func[]"> - <?php - if (preg_match('@char|blob|text|set|enum@i', $fields_type[$i])) { - foreach($textfunctions AS $k => $fc) { - echo "\n" . ' ' - . '<option value="' . htmlspecialchars($fc) . '">' . htmlspecialchars($fc) . '</option>'; - } // end while - } else { - foreach($numfunctions AS $k => $fc) { - echo "\n" . ' ' - . '<option value="' . htmlspecialchars($fc) . '">' . htmlspecialchars($fc) . '</option>'; - } // end while - } // end if... else... - echo "\n"; - ?> + <?php + if (preg_match('@char|blob|text|set|enum@i', $fields_type[$i])) { + foreach($textfunctions AS $k => $fc) { + echo "\n" . ' ' + . '<option value="' . htmlspecialchars($fc) . '">' . htmlspecialchars($fc) . '</option>'; + } // end while + } else { + foreach($numfunctions AS $k => $fc) { + echo "\n" . ' ' + . '<option value="' . htmlspecialchars($fc) . '">' . htmlspecialchars($fc) . '</option>'; + } // end while + } // end if... else... + echo "\n"; + ?> </select> </td> <td bgcolor="<?php echo $bgcolor; ?>"> - <?php - // <markus@noga.de> - $field = $fields_list[$i]; + <?php + // <markus@noga.de> + $field = $fields_list[$i]; - // do not use require_once here - require('./libraries/get_foreign.lib.php'); + // do not use require_once here + require('./libraries/get_foreign.lib.php'); - echo "\n"; - // we got a bug report: in some cases, even if $disp is true, - // there are no rows, so we add a fetch_array + echo "\n"; + // we got a bug report: in some cases, even if $disp is true, + // there are no rows, so we add a fetch_array - if ($foreigners && isset($foreigners[$field]) && isset($disp) && $disp && @PMA_mysql_fetch_array($disp)) { - // f o r e i g n k e y s - echo ' <select name="fields[]">' . "\n"; - // go back to first row - mysql_data_seek($disp,0); - echo PMA_foreignDropdown($disp, $foreign_field, $foreign_display, $data, 100); - echo ' </select>' . "\n"; - } else if (isset($foreign_link) && $foreign_link == true) { - ?> + if ($foreigners && isset($foreigners[$field]) && isset($disp) && $disp && PMA_DBI_fetch_row($disp)) { + // f o r e i g n k e y s + echo ' <select name="fields[]">' . "\n"; + // go back to first row + mysql_data_seek($disp,0); // !UNWRAPPED FUNCTION! + echo PMA_foreignDropdown($disp, $foreign_field, $foreign_display, $data, 100); + echo ' </select>' . "\n"; + } else if (isset($foreign_link) && $foreign_link == true) { + ?> <input type="text" name="fields[]" id="field_<?php echo md5($field); ?>[]" class="textfield" /> <script type="text/javascript" language="javascript"> document.writeln('<a target="_blank" onclick="window.open(this.href, \'foreigners\', \'width=640,height=240,scrollbars=yes\'); return false" href="browse_foreigners.php?<?php echo PMA_generate_common_url($db, $table); ?>&field=<?php echo urlencode($field); ?>"><?php echo str_replace("'", "\'", $titles['Browse']); ?></a>'); </script> - <?php - } else if (substr($fields_type[$i], 0, 3)=='enu'){ - // e n u m s - $enum_value=explode(', ', str_replace("'", '', substr($fields_type[$i], 5, -1))); - echo ' <select name="fields[]">' . "\n"; - echo ' <option value=""></option>' . "\n"; - $cnt_enum_value = count($enum_value); - for ($j=0; $j<$cnt_enum_value;$j++){ - echo ' <option value="' . $enum_value[$j] . '">' . $enum_value[$j] . '</option>'; - } // end for - echo ' </select>' . "\n"; - } else { - // o t h e r c a s e s - echo ' <input type="text" name="fields[]" size="40" class="textfield" />' . "\n"; - } + <?php + } else if (substr($fields_type[$i], 0, 3)=='enu'){ + // e n u m s + $enum_value=explode(', ', str_replace("'", '', substr($fields_type[$i], 5, -1))); + echo ' <select name="fields[]">' . "\n"; + echo ' <option value=""></option>' . "\n"; + $cnt_enum_value = count($enum_value); + for ($j=0; $j<$cnt_enum_value;$j++){ + echo ' <option value="' . $enum_value[$j] . '">' . $enum_value[$j] . '</option>'; + } // end for + echo ' </select>' . "\n"; + } else { + // o t h e r c a s e s + echo ' <input type="text" name="fields[]" size="40" class="textfield" />' . "\n"; + } - ?> + ?> <input type="hidden" name="names[]" value="<?php echo htmlspecialchars($fields_list[$i]); ?>" /> <input type="hidden" name="types[]" value="<?php echo $fields_type[$i]; ?>" /> </td> </tr> - <?php - } // end for - echo "\n"; - ?> + <?php + } // end for + echo "\n"; + ?> </table><br /> </li> <li> <?php echo $strDisplayOrder; ?><br /> <select name="orderField" style="vertical-align: middle"> <option value="--nil--"></option> - <?php - echo "\n"; - for ($i = 0; $i < $fields_cnt; $i++) { - echo ' '; - echo '<option value="' . htmlspecialchars($fields_list[$i]) . '">' . htmlspecialchars($fields_list[$i]) . '</option>' . "\n"; - } // end for - ?> + <?php + echo "\n"; + for ($i = 0; $i < $fields_cnt; $i++) { + echo ' '; + echo '<option value="' . htmlspecialchars($fields_list[$i]) . '">' . htmlspecialchars($fields_list[$i]) . '</option>' . "\n"; + } // end for + ?> </select> <input type="radio" name="order" value="ASC" checked="checked" /> <?php echo $strAscending; ?> @@ -226,8 +221,7 @@ if (!isset($param) || $param[0] == '') { <input type="hidden" name="max_number_of_fields" value="<?php echo $fields_cnt; ?>" /> <input type="submit" name="submit" value="<?php echo $strGo; ?>" /> </form> - <?php - } // end if + <?php require_once('./footer.inc.php'); } diff --git a/transformation_wrapper.php b/transformation_wrapper.php index ca79a2da29..d798ba392b 100644 --- a/transformation_wrapper.php +++ b/transformation_wrapper.php @@ -26,16 +26,14 @@ require_once('./libraries/db_table_exists.lib.php'); /** * Get the list of the fields of the current table */ -PMA_mysql_select_db($db); -$table_def = PMA_mysql_query('SHOW FIELDS FROM ' . PMA_backquote($table)); +PMA_DBI_select_db($db); +$table_def = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table)); if (isset($primary_key)) { - $local_query = 'SELECT * FROM ' . PMA_backquote($table) . ' WHERE ' . $primary_key; - $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', ''); - $row = PMA_mysql_fetch_array($result); + $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($table) . ' WHERE ' . $primary_key . ';'); + $row = PMA_DBI_fetch_assoc($result); } else { - $local_query = 'SELECT * FROM ' . PMA_backquote($table) . ' LIMIT 1'; - $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', ''); - $row = PMA_mysql_fetch_array($result); + $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($table) . ' LIMIT 1;'); + $row = PMA_DBI_fetch_assoc($result); } // No row returned diff --git a/user_password.php b/user_password.php index 0de2edeb0d..56b1a4202b 100644 --- a/user_password.php +++ b/user_password.php @@ -14,7 +14,7 @@ require_once('./libraries/common.lib.php'); * script */ if (!$cfg['ShowChgPassword']) { - $cfg['ShowChgPassword'] = @PMA_mysql_query('USE mysql', $userlink); + $cfg['ShowChgPassword'] = PMA_DBI_select_db('mysql'); } if ($cfg['Server']['auth_type'] == 'config' || !$cfg['ShowChgPassword']) { require_once('./header.inc.php'); @@ -50,7 +50,7 @@ if (isset($nopass)) { $sql_query = 'SET password = ' . (($pma_pw == '') ? '\'\'' : 'PASSWORD(\'' . preg_replace('@.@s', '*', $pma_pw) . '\')'); $local_query = 'SET password = ' . (($pma_pw == '') ? '\'\'' : 'PASSWORD(\'' . PMA_sqlAddslashes($pma_pw) . '\')'); - $result = @PMA_mysql_query($local_query) or PMA_mysqlDie('', '', FALSE, $err_url); + $result = @PMA_DBI_try_query($local_query) or PMA_mysqlDie(PMA_DBI_getError(), $sql_query, FALSE, $err_url); // Changes password cookie if required if ($cfg['Server']['auth_type'] == 'cookie') { |