本文整理汇总了PHP中PMA_mysql_fetch_array函数的典型用法代码示例。如果您正苦于以下问题:PHP PMA_mysql_fetch_array函数的具体用法?PHP PMA_mysql_fetch_array怎么用?PHP PMA_mysql_fetch_array使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PMA_mysql_fetch_array函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: PMA_duplicate_table
/**
* Inserts existing entries in a PMA_* table by reading a value from an old entry
*
* @param string The array index, which Relation feature to check
* ('relwork', 'commwork', ...)
* @param string The array index, which PMA-table to update
* ('bookmark', 'relation', ...)
* @param array Which fields will be SELECT'ed from the old entry
* @param array Which fields will be used for the WHERE query
* (array('FIELDNAME' => 'FIELDVALUE'))
* @param array Which fields will be used as new VALUES. These are the important
* keys which differ from the old entry.
* (array('FIELDNAME' => 'NEW FIELDVALUE'))
* @global string relation variable
*
* @author Garvin Hicking <me@supergarv.de>
*/
function PMA_duplicate_table($work, $pma_table, $get_fields, $where_fields, $new_fields)
{
global $cfgRelation;
$last_id = -1;
if ($cfgRelation[$work]) {
$select_parts = array();
$row_fields = array();
foreach ($get_fields as $nr => $get_field) {
$select_parts[] = PMA_backquote($get_field);
$row_fields[$get_field] = 'cc';
}
$where_parts = array();
foreach ($where_fields as $_where => $_value) {
$where_parts[] = PMA_backquote($_where) . ' = \'' . PMA_sqlAddslashes($_value) . '\'';
}
$new_parts = array();
$new_value_parts = array();
foreach ($new_fields as $_where => $_value) {
$new_parts[] = PMA_backquote($_where);
$new_value_parts[] = PMA_sqlAddslashes($_value);
}
$table_copy_query = 'SELECT ' . implode(', ', $select_parts) . ' FROM ' . PMA_backquote($cfgRelation[$pma_table]) . ' 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)) {
$value_parts = array();
foreach ($table_copy_row as $_key => $_val) {
if (isset($row_fields[$_key]) && $row_fields[$_key] == 'cc') {
$value_parts[] = PMA_sqlAddslashes($_val);
}
}
$new_table_query = 'INSERT IGNORE INTO ' . PMA_backquote($cfgRelation[$pma_table]) . ' (' . implode(', ', $select_parts) . ', ' . implode(', ', $new_parts) . ')' . ' VALUES ' . ' (\'' . implode('\', \'', $value_parts) . '\', \'' . implode('\', \'', $new_value_parts) . '\')';
$new_table_rs = PMA_query_as_cu($new_table_query);
$last_id = @function_exists('mysql_insert_id') ? @mysql_insert_id() : -1;
}
// end while
return $last_id;
}
return true;
}
示例2: PMA_displayPrivTable
/**
* Displays the privileges form table
*
* @param string the database
* @param string the table
* @param boolean wheather to display the submit button or not
* @param int the indenting level of the code
*
* @global array the phpMyAdmin configuration
* @global ressource the database connection
*
* @return void
*/
function PMA_displayPrivTable($db = '*', $table = '*', $submit = TRUE, $indent = 0)
{
global $cfg, $userlink;
if ($db == '*') {
$table = '*';
}
$spaces = '';
for ($i = 0; $i < $indent; $i++) {
$spaces .= ' ';
}
if (isset($GLOBALS['username'])) {
$username = $GLOBALS['username'];
$hostname = $GLOBALS['hostname'];
if ($db == '*') {
$sql_query = 'SELECT * FROM `user` WHERE `User` = "' . PMA_sqlAddslashes($username) . '" AND `Host` = "' . $hostname . '";';
} else {
if ($table == '*') {
$sql_query = 'SELECT * FROM `db` WHERE `User` = "' . PMA_sqlAddslashes($username) . '" AND `Host` = "' . $hostname . '" AND `Db` = "' . $db . '";';
} 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);
}
@mysql_free_result($res);
}
if (empty($row)) {
if ($table == '*') {
if ($db == '*') {
$sql_query = 'SHOW COLUMNS FROM `mysql`.`user`;';
} 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)) {
if (substr($row1[0], 0, 4) == 'max_') {
$row[$row1[0]] = 0;
} else {
$row[$row1[0]] = 'N';
}
}
mysql_free_result($res);
} else {
$row = array('Table_priv' => '');
}
}
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);
mysql_free_result($res);
$av_grants = explode('\',\'', substr($row1['Type'], strpos($row1['Type'], '(') + 2, strpos($row1['Type'], ')') - strpos($row1['Type'], '(') - 3));
unset($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);
}
mysql_free_result($res);
unset($res);
unset($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)) {
$row1[1] = explode(',', $row1[1]);
foreach ($row1[1] as $current) {
$columns[$row1[0]][$current] = TRUE;
}
}
mysql_free_result($res);
unset($res);
//.........这里部分代码省略.........
示例3:
?>
</select>
</td>
<td bgcolor="<?php
echo $bgcolor;
?>
">
<?php
// <markus@noga.de>
$field = $fields_list[$i];
// 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
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) {
?>
<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
示例4: foreach
foreach ($array_sh_page as $key => $temp_sh_page) {
$drag_x = $temp_sh_page['x'];
$drag_y = $temp_sh_page['y'];
$draginit .= ' Drag.init(getElement("table_' . $i . '"), null, 0, parseInt(myid.style.width)-2, 0, parseInt(myid.style.height)-5);' . "\n";
$draginit .= ' getElement("table_' . $i . '").onDrag = function (x, y) { document.edcoord.elements["c_table_' . $i . '[x]"].value = parseInt(x); document.edcoord.elements["c_table_' . $i . '[y]"].value = parseInt(y) }' . "\n";
$draginit .= ' getElement("table_' . $i . '").style.left = "' . $drag_x . 'px";' . "\n";
$draginit .= ' getElement("table_' . $i . '").style.top = "' . $drag_y . 'px";' . "\n";
$reset_draginit .= ' getElement("table_' . $i . '").style.left = "2px";' . "\n";
$reset_draginit .= ' getElement("table_' . $i . '").style.top = "' . 15 * $i . 'px";' . "\n";
$reset_draginit .= ' document.edcoord.elements["c_table_' . $i . '[x]"].value = "2"' . "\n";
$reset_draginit .= ' document.edcoord.elements["c_table_' . $i . '[y]"].value = "' . 15 * $i . '"' . "\n";
$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_cnt = mysql_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";
}
echo '</div>' . "\n";
mysql_free_result($fields_rs);
$i++;
}
?>
</div>
<script type="text/javascript">
<!--
function init() {
refreshLayout();
myid = getElement('pdflayout');
<?php
echo $draginit;
示例5: PMA_displayTableBody
/**
* Displays the body of the results table
*
* @param integer the link id associated to the query which results have
* to be displayed
* @param array which elements to display
* @param array the list of relations
* @param array the analyzed query
*
* @return boolean always true
*
* @global string the current language
* @global string the current charset for MySQL
* @global integer the server to use (refers to the number in the
* configuration file)
* @global string the database name
* @global string the table name
* @global string the sql query
* @global string the url to go back in case of errors
* @global integer the current position in results
* @global integer the maximum number of rows per page
* @global array the list of fields properties
* @global integer the total number of fields returned by the sql query
* @global array informations used with vertical display mode
* @global string the display mode (horizontal/vertical/horizontalflipped)
* @global integer the number of row to display between two table headers
* @global boolean whether to limit the number of displayed characters of
* text type fields or not
*
* @access private
*
* @see PMA_displayTable()
*/
function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql)
{
global $lang, $convcharset, $server, $db, $table;
global $goto;
global $sql_query, $pos, $session_max_rows, $fields_meta, $fields_cnt;
global $vertical_display, $disp_direction, $repeat_cells, $highlight_columns;
global $dontlimitchars;
global $row;
// mostly because of browser transformations, to make the row-data accessible in a plugin
if (!is_array($map)) {
$map = array();
}
?>
<!-- Results table body -->
<?php
echo "\n";
$row_no = 0;
$vertical_display['edit'] = array();
$vertical_display['delete'] = array();
$vertical_display['data'] = array();
$vertical_display['row_delete'] = array();
// Correction uva 19991216 in the while below
// Previous code assumed that all tables have keys, specifically that
// the phpMyAdmin GUI should support row delete/edit only for such
// tables.
// Although always using keys is arguably the prescribed way of
// defining a relational table, it is not required. This will in
// particular be violated by the novice.
// We want to encourage phpMyAdmin usage by such novices. So the code
// below has been changed to conditionally work as before when the
// table being displayed has one or more keys; but to display
// delete/edit options correctly for tables without keys.
// 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)) {
// lem9: "vertical display" mode stuff
if ($row_no != 0 && $repeat_cells != 0 && !($row_no % $repeat_cells) && ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped')) {
echo '<tr>' . "\n";
for ($foo_i = 0; $foo_i < $vertical_display['emptypre']; $foo_i++) {
echo ' <td> </td>' . "\n";
}
foreach ($vertical_display['desc'] as $key => $val) {
echo $val;
}
for ($foo_i = 0; $foo_i < $vertical_display['emptyafter']; $foo_i++) {
echo ' <td> </td>' . "\n";
}
echo '</tr>' . "\n";
}
// end if
if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
$bgcolor = '#ffffff';
} else {
$bgcolor = $row_no % 2 ? $GLOBALS['cfg']['BgcolorOne'] : $GLOBALS['cfg']['BgcolorTwo'];
}
if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
// loic1: pointer code part
$on_mouse = '';
if (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
if ($GLOBALS['cfg']['BrowsePointerColor'] != '') {
$on_mouse = ' onmouseover="setPointer(this, ' . $row_no . ', \'over\', \'' . $bgcolor . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"' . ' onmouseout="setPointer(this, ' . $row_no . ', \'out\', \'' . $bgcolor . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"';
}
if ($GLOBALS['cfg']['BrowseMarkerColor'] != '') {
$on_mouse .= ' onmousedown="setPointer(this, ' . $row_no . ', \'click\', \'' . $bgcolor . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"';
}
}
// end if
//.........这里部分代码省略.........
示例6: PMA_generate_common_url
if ($num_dbs == 1) {
$db = $dblist[0];
$tables = @PMA_mysql_list_tables($db);
$num_tables = $tables ? @mysql_numrows($tables) : 0;
$common_url_query = PMA_generate_common_url($db);
if ($num_tables) {
$num_tables_disp = $num_tables;
} else {
$num_tables_disp = '-';
}
// Get additional infomation about tables for tooltip
if ($cfg['ShowTooltip'] && PMA_MYSQL_INT_VERSION >= 32303 && $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)) {
$tooltip_name[$tmp['Name']] = !empty($tmp['Comment']) ? $tmp['Comment'] . ' ' : '';
$tmp['Comment'] = $cfg['ShowTooltipAliasTB'] ? $tmp['Name'] : $tmp['Comment'];
$tooltip[$tmp['Name']] = (!empty($tmp['Comment']) ? $tmp['Comment'] . ' ' : '') . '(' . (isset($tmp['Rows']) ? $tmp['Rows'] : '0') . ' ' . $strRows . ')';
}
// end while
}
// end if
// garvin: Get comments from PMA comments table
$db_tooltip = '';
if ($cfg['ShowTooltip'] && $cfgRelation['commwork']) {
$tmp_db_tooltip = PMA_getComments($db);
if (is_array($tmp_db_tooltip)) {
$db_tooltip = implode(' ', $tmp_db_tooltip);
}
}
示例7: PMA_setMIME
/**
* Set a single mimetype to a certain value.
*
* @param string the name of the db
* @param string the name of the table
* @param string the name of the column
* @param string the mimetype of the column
* @param string the transformation of the column
* @param string the transformation options of the column
* @param string (optional) force delete, will erase any existing comments for this column
*
* @return boolean true, if comment-query was made.
*
* @global array the list of relations settings
*
* @access public
*/
function PMA_setMIME($db, $table, $key, $mimetype, $transformation, $transformation_options, $forcedelete = false)
{
global $cfgRelation;
$test_qry = 'SELECT mimetype, ' . PMA_backquote('comment') . ' FROM ' . PMA_backquote($cfgRelation['column_info']) . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'' . ' AND column_name = \'' . PMA_sqlAddslashes($key) . '\'';
$test_rs = PMA_query_as_cu($test_qry);
if ($test_rs && mysql_num_rows($test_rs) > 0) {
$row = @PMA_mysql_fetch_array($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']) . ' SET mimetype = \'' . PMA_sqlAddslashes($mimetype) . '\',' . ' transformation = \'' . PMA_sqlAddslashes($transformation) . '\',' . ' transformation_options = \'' . PMA_sqlAddslashes($transformation_options) . '\'' . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'' . ' AND column_name = \'' . PMA_sqlAddslashes($key) . '\'';
} else {
$upd_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['column_info']) . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'' . ' AND column_name = \'' . PMA_sqlAddslashes($key) . '\'';
}
} else {
if (strlen($mimetype) > 0 || strlen($transformation) > 0 || strlen($transformation_options) > 0) {
$upd_query = 'INSERT INTO ' . PMA_backquote($cfgRelation['column_info']) . ' (db_name, table_name, column_name, mimetype, transformation, transformation_options) ' . ' VALUES(' . '\'' . PMA_sqlAddslashes($db) . '\',' . '\'' . PMA_sqlAddslashes($table) . '\',' . '\'' . PMA_sqlAddslashes($key) . '\',' . '\'' . PMA_sqlAddslashes($mimetype) . '\',' . '\'' . PMA_sqlAddslashes($transformation) . '\',' . '\'' . PMA_sqlAddslashes($transformation_options) . '\')';
}
}
if (isset($upd_query)) {
$upd_rs = PMA_query_as_cu($upd_query);
unset($upd_query);
return true;
} else {
return false;
}
}
示例8: PMA_backquote
$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);
$tables[] = $sts_tmp;
} else {
// table in use
$tables[] = array('Name' => $tmp[0]);
}
}
mysql_free_result($db_info_result);
$sot_ready = 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);
if ($db_info_result != FALSE && mysql_num_rows($db_info_result) > 0) {
while ($sts_tmp = PMA_mysql_fetch_array($db_info_result)) {
$tables[] = $sts_tmp;
}
mysql_free_result($db_info_result);
}
}
$num_tables = isset($tables) ? count($tables) : 0;
/**
* Displays top menu links
*/
echo '<!-- Top menu links -->' . "\n";
require './db_details_links.php';
示例9: PMA_exportData
/**
* Outputs the content of a table
*
* @param string the database name
* @param string the table name
* @param string the end of line sequence
* @param string the url to go back in case of error
* @param string SQL query for obtaining data
*
* @return bool Whether it suceeded
*
* @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);
for ($i = 0; $i < $columns_cnt; $i++) {
$columns[$i] = stripslashes(mysql_field_name($result, $i));
}
unset($i);
$buffer = ' <!-- ' . $GLOBALS['strTable'] . ' ' . $table . ' -->' . $crlf;
if (!PMA_exportOutputHandler($buffer)) {
return FALSE;
}
while ($record = PMA_mysql_fetch_array($result, MYSQL_ASSOC)) {
$buffer = ' <' . $table . '>' . $crlf;
for ($i = 0; $i < $columns_cnt; $i++) {
// There is no way to dectect a "NULL" value with PHP3
if (isset($record[$columns[$i]]) && (!function_exists('is_null') || !is_null($record[$columns[$i]]))) {
$buffer .= ' <' . $columns[$i] . '>' . htmlspecialchars(stripslashes($record[$columns[$i]])) . '</' . $columns[$i] . '>' . $crlf;
}
}
$buffer .= ' </' . $table . '>' . $crlf;
if (!PMA_exportOutputHandler($buffer)) {
return FALSE;
}
}
mysql_free_result($result);
return TRUE;
}
示例10: PMA_generate_common_hidden_inputs
?>
<form method="post" action="tbl_relation.php">
<?php
echo PMA_generate_common_hidden_inputs($db, $table);
?>
<input type="hidden" name="submit_show" value="true" />
<p><?php
echo $strChangeDisplay . ': ';
?>
<select name="display_field" onchange="this.form.submit();">
<option value="">---</option>
<?php
echo "\n";
mysql_data_seek($col_rs, 0);
while ($row = @PMA_mysql_fetch_array($col_rs)) {
echo ' <option value="' . htmlspecialchars($row['Field']) . '"';
if (isset($disp) && $row['Field'] == $disp) {
echo ' selected="selected"';
}
echo '>' . htmlspecialchars($row['Field']) . '</option>' . "\n";
}
// end while
?>
</select>
<script type="text/javascript" language="javascript">
<!--
// Fake js to allow the use of the <noscript> tag
//-->
</script>
<noscript>
示例11: PMA_generate_common_hidden_inputs
<li>
<form method="post" action="pdf_schema.php">
<?php
echo PMA_generate_common_hidden_inputs($db);
?>
<?php
echo $strDisplayPDF;
?>
:<br />
<?php
echo $strPageNumber;
?>
<select name="pdf_page_number">
<?php
while ($pages = @PMA_mysql_fetch_array($test_rs)) {
echo "\n" . ' ' . '<option value="' . $pages['page_nr'] . '">' . $pages['page_nr'] . ': ' . $pages['page_descr'] . '</option>';
}
// end while
echo "\n";
?>
</select><br />
<input type="checkbox" name="show_grid" id="show_grid_opt" />
<label for="show_grid_opt"><?php
echo $strShowGrid;
?>
</label><br />
<input type="checkbox" name="show_color" id="show_color_opt" checked="checked" />
<label for="show_color_opt"><?php
echo $strShowColor;
?>
示例12: PMA_getTableDef
/**
* Returns $table's CREATE definition
*
* @param string the database name
* @param string the table name
* @param string the end of line sequence
* @param string the url to go back in case of error
* @param boolean whether to include creation/update/check dates
*
* @return string resulting schema
*
* @global boolean whether to add 'drop' statements or not
* @global boolean whether to use backquotes to allow the use of special
* characters in database, table and fields names or not
*
* @access public
*/
function PMA_getTableDef($db, $table, $crlf, $error_url, $show_dates = false)
{
global $drop;
global $use_backquotes;
global $cfgRelation;
global $sql_constraints;
$schema_create = '';
$auto_increment = '';
$new_crlf = $crlf;
$result = PMA_mysql_query('SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \'' . PMA_sqlAddslashes($table) . '\'');
if ($result != FALSE) {
if (mysql_num_rows($result) > 0) {
$tmpres = PMA_mysql_fetch_array($result);
if (isset($GLOBALS['auto_increment']) && !empty($tmpres['Auto_increment'])) {
$auto_increment .= ' AUTO_INCREMENT=' . $tmpres['Auto_increment'] . ' ';
}
if ($show_dates && isset($tmpres['Create_time']) && !empty($tmpres['Create_time'])) {
$schema_create .= '# ' . $GLOBALS['strStatCreateTime'] . ': ' . PMA_localisedDate(strtotime($tmpres['Create_time'])) . $crlf;
$new_crlf = '#' . $crlf . $crlf;
}
if ($show_dates && isset($tmpres['Update_time']) && !empty($tmpres['Update_time'])) {
$schema_create .= '# ' . $GLOBALS['strStatUpdateTime'] . ': ' . PMA_localisedDate(strtotime($tmpres['Update_time'])) . $crlf;
$new_crlf = '#' . $crlf . $crlf;
}
if ($show_dates && isset($tmpres['Check_time']) && !empty($tmpres['Check_time'])) {
$schema_create .= '# ' . $GLOBALS['strStatCheckTime'] . ': ' . PMA_localisedDate(strtotime($tmpres['Check_time'])) . $crlf;
$new_crlf = '#' . $crlf . $crlf;
}
mysql_free_result($result);
}
}
$schema_create .= $new_crlf;
if (!empty($drop)) {
$schema_create .= 'DROP TABLE IF EXISTS ' . PMA_backquote($table, $use_backquotes) . ';' . $crlf;
}
// 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');
} else {
PMA_mysql_query('SET SQL_QUOTE_SHOW_CREATE = 0');
}
$result = PMA_mysql_query('SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table));
if ($result != FALSE && mysql_num_rows($result) > 0) {
$tmpres = PMA_mysql_fetch_array($result);
// Fix for case problems with winwin, thanks to
// Pawe³ Szczepañski <pauluz at users.sourceforge.net>
$pos = strpos($tmpres[1], ' (');
// Fix a problem with older versions of mysql
// Find the first opening parenthesys, i.e. that after the name
// of the table
$pos2 = strpos($tmpres[1], '(');
// Old mysql did not insert a space after table name
// in query "show create table ..."!
if ($pos2 != $pos + 1) {
// This is the real position of the first character after
// the name of the table
$pos = $pos2;
// Old mysql did not even put newlines and indentation...
$tmpres[1] = str_replace(",", ",\n ", $tmpres[1]);
}
$tmpres[1] = substr($tmpres[1], 0, 13) . ($use_backquotes ? PMA_backquote($tmpres[0]) : $tmpres[0]) . substr($tmpres[1], $pos);
$tmpres[1] = str_replace("\n", $crlf, $tmpres[1]);
if (preg_match_all('((,\\r?\\n[\\s]*(CONSTRAINT|FOREIGN[\\s]*KEY)[^\\r\\n,]+)+)', $tmpres[1], $regs)) {
if (!isset($sql_constraints)) {
if (isset($GLOBALS['no_constraints_comments'])) {
$sql_constraints = '';
} else {
$sql_constraints = $crlf . '#' . $crlf . '# ' . $GLOBALS['strConstraintsForDumped'] . $crlf . '#' . $crlf;
}
}
if (!isset($GLOBALS['no_constraints_comments'])) {
$sql_constraints .= $crlf . '#' . $crlf . '# ' . $GLOBALS['strConstraintsForTable'] . ' ' . PMA_backquote($table) . $crlf . '#' . $crlf;
}
$sql_constraints .= 'ALTER TABLE ' . PMA_backquote($table) . $crlf . preg_replace('/(,\\r?\\n|^)([\\s]*)(CONSTRAINT|FOREIGN[\\s]*KEY)/', '\\1\\2ADD \\3', substr($regs[0][0], 2)) . ";\n";
$tmpres[1] = preg_replace('((,\\r?\\n[\\s]*(CONSTRAINT|FOREIGN[\\s]*KEY)[^\\r\\n,]+)+)', '', $tmpres[1]);
}
$schema_create .= $tmpres[1];
}
$schema_create .= $auto_increment;
mysql_free_result($result);
return $schema_create;
}
示例13: PMA_sqlAddslashes
// end if
}
// end if
// If the user has Create priv on a inexistant db, show him in the dialog
// 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_mysql_query($local_query, $dbh);
// Debug: or PMA_mysqlDie('', $local_query, FALSE);
if ($rs_usr) {
$re0 = '(^|(\\\\\\\\)+|[^\\])';
// non-escaped wildcards
$re1 = '(^|[^\\])(\\\\)+';
// escaped wildcards
while ($row = PMA_mysql_fetch_array($rs_usr)) {
if (ereg($re0 . '(%|_)', $row['Db']) || !PMA_mysql_select_db(ereg_replace($re1 . '(%|_)', '\\1\\3', $row['Db']), $userlink) && @mysql_errno() != 1044) {
$db_to_create = ereg_replace($re0 . '%', '\\1...', ereg_replace($re0 . '_', '\\1?', $row['Db']));
$db_to_create = ereg_replace($re1 . '(%|_)', '\\1\\3', $db_to_create);
$is_create_priv = TRUE;
break;
}
// end if
}
// end while
mysql_free_result($rs_usr);
} else {
// 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;
示例14: PMA_exportStructure
function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = false, $do_comments = false, $do_mime = false, $dates = false)
{
global $cfgRelation;
/**
* Gets fields properties
*/
PMA_mysql_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);
$fields_cnt = mysql_num_rows($result);
// Check if we can use Relations (Mike Beck)
if ($do_relation && !empty($cfgRelation['relation'])) {
// Find which tables are related with the current one and write it in
// an array
$res_rel = PMA_getForeigners($db, $table);
if ($res_rel && count($res_rel) > 0) {
$have_rel = TRUE;
} else {
$have_rel = FALSE;
}
} else {
$have_rel = FALSE;
}
// end if
/**
* 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);
$unique_keys = array();
while ($key = PMA_mysql_fetch_array($keys_result)) {
if ($key['Non_unique'] == 0) {
$unique_keys[] = $key['Column_name'];
}
}
/**
* Displays the table structure
*/
$buffer = $crlf . '%' . $crlf . '% ' . $GLOBALS['strStructure'] . ': ' . $table . $crlf . '%' . $crlf . ' \\begin{longtable}{';
if (!PMA_exportOutputHandler($buffer)) {
return FALSE;
}
$columns_cnt = 4;
$alignment = '|l|c|c|c|';
if ($do_relation && $have_rel) {
$columns_cnt++;
$alignment .= 'l|';
}
if ($do_comments && $cfgRelation['commwork']) {
$columns_cnt++;
$alignment .= 'l|';
}
if ($do_mime && $cfgRelation['mimework']) {
$columns_cnt++;
$alignment .= 'l|';
}
$buffer = $alignment . '} ' . $crlf;
$header .= ' \\hline ';
$header .= '\\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strField'] . '}} & \\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strType'] . '}} & \\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strNull'] . '}} & \\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strDefault'] . '}}';
if ($do_relation && $have_rel) {
$header .= ' & \\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strLinksTo'] . '}}';
}
if ($do_comments && $cfgRelation['commwork']) {
$header .= ' & \\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strComments'] . '}}';
$comments = PMA_getComments($db, $table);
}
if ($do_mime && $cfgRelation['mimework']) {
$header .= ' & \\multicolumn{1}{|c|}{\\textbf{MIME}}';
$mime_map = PMA_getMIME($db, $table, true);
}
$local_buffer = PMA_texEscape($table);
// Table caption for first page and label
if (isset($GLOBALS['latex_caption'])) {
$buffer .= ' \\caption{' . str_replace('__TABLE__', PMA_texEscape($table), $GLOBALS['latex_structure_caption']) . '} \\label{' . str_replace('__TABLE__', $table, $GLOBALS['latex_structure_label']) . '} \\\\' . $crlf;
}
$buffer .= $header . ' \\\\ \\hline \\hline' . $crlf . '\\endfirsthead' . $crlf;
// Table caption on next pages
if (isset($GLOBALS['latex_caption'])) {
$buffer .= ' \\caption{' . str_replace('__TABLE__', PMA_texEscape($table), $GLOBALS['latex_structure_continued_caption']) . '} \\\\ ' . $crlf;
}
$buffer .= $header . ' \\\\ \\hline \\hline \\endhead \\endfoot ';
if (!PMA_exportOutputHandler($buffer)) {
return FALSE;
}
while ($row = PMA_mysql_fetch_array($result)) {
$type = $row['Type'];
// reformat mysql query output - staybyte - 9. June 2001
// loic1: set or enum types: slashes single quotes inside options
if (eregi('^(set|enum)\\((.+)\\)$', $type, $tmp)) {
$tmp[2] = substr(ereg_replace('([^,])\'\'', '\\1\\\'', ',' . $tmp[2]), 1);
$type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
$type_nowrap = '';
$binary = 0;
$unsigned = 0;
$zerofill = 0;
} else {
$type_nowrap = ' nowrap="nowrap"';
$type = eregi_replace('BINARY', '', $type);
$type = eregi_replace('ZEROFILL', '', $type);
$type = eregi_replace('UNSIGNED', '', $type);
//.........这里部分代码省略.........
示例15: PMA_checkParameters
<?php
/* $Id: tbl_properties_table_info.php,v 2.3 2003/12/29 17:15:14 rabus Exp $ */
// vim: expandtab sw=4 ts=4 sts=4:
// this should be recoded as functions, to avoid messing with global
// variables
// Check parameters
require_once './libraries/common.lib.php';
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);
$tbl_type = strtoupper($showtable['Type']);
$tbl_charset = empty($showtable['Collation']) ? '' : $showtable['Collation'];
$table_info_num_rows = isset($showtable['Rows']) ? $showtable['Rows'] : 0;
$show_comment = isset($showtable['Comment']) ? $showtable['Comment'] : '';
$auto_increment = isset($showtable['Auto_increment']) ? $showtable['Auto_increment'] : '';
$tmp = explode(' ', $showtable['Create_options']);
$tmp_cnt = count($tmp);
for ($i = 0; $i < $tmp_cnt; $i++) {
$tmp1 = explode('=', $tmp[$i]);
if (isset($tmp1[1])) {
${$tmp1}[0] = $tmp1[1];
}
}
// end for
unset($tmp1, $tmp);