【php开源代码栏目提醒】:以下是网学会员为您推荐的php开源代码-db_details_qbe.php,希望本篇文章对您学习有所帮助。
<?php
/* $Id: db_details_qbe.php,v 2.21 2006/01/25 13:48:26 lem9 Exp $ */
// vim: expandtab sw=4 ts=4 sts=4:
/**
* query by example the whole database
*/
/**
* requirements
*/
require_once('./libraries/common.lib.php');
require_once('./libraries/relation.lib.php');
/**
* Gets the relation settings
*/
$cfgRelation = PMA_getRelationsParam();
/**
* A query has been submitted -> execute it, else display the headers
*/
if ( isset( $_REQUEST['submit_sql'] )
&& preg_match('@^SELECT@i', $_REQUEST['encoded_sql_query']) ) {
$goto = 'db_details.php';
$zero_rows = htmlspecialchars($GLOBALS['strSuccess']);
$sql_query = urldecode($_REQUEST['encoded_
sql_query']);
require('./sql.php');
exit();
} else {
$sub_part = '_qbe';
require('./libraries/db_details_common.inc.php');
$url_query .= '&goto=db_details_qbe.php';
$url_params['goto'] = 'db_details_qbe.php';
require('./libraries/db_details_db_info.inc.php');
}
if ( isset($_REQUEST['submit_sql'] )
&& ! preg_match('@^SELECT@i', $_REQUEST['encoded_sql_query']) ) {
echo '<div class="warning">' . $GLOBALS['strHaveToShow'] . '</div>';
}
/**
* Initialize some variables
*/
$col_cnt = isset( $_REQUEST['col_cnt'] ) ? (int) $_REQUEST['col_cnt'] : 3;
$add_col = isset( $_REQUEST['add_col'] ) ? (int) $_REQUEST['add_col'] : 0;
$add_row = isset( $_REQUEST['add_row'] ) ? (int) $_REQUEST['add_row'] : 0;
$rows = isset( $_REQUEST['rows'] ) ? (int) $_REQUEST['rows'] : 0;
$ins_col = isset( $_REQUEST['ins_col'] ) ? $_REQUEST['ins_col'] : array();
$del_col = isset( $_REQUEST['del_col'] ) ? $_REQUEST['del_col'] : array();
$prev_criteria = isset( $_REQUEST['prev_criteria'] )
? $_REQUEST['prev_criteria']
: array();
$criteria = isset( $_REQUEST['criteria'] )
? $_REQUEST['criteria']
: array_fill(0, $col_cnt, '');
$ins_row = isset( $_REQUEST['ins_row'] )
? $_REQUEST['ins_row']
: array_fill(0, $col_cnt, '');
$del_row = isset( $_REQUEST['del_row'] )
? $_REQUEST['del_row']
: array_fill(0, $col_cnt, '');
$and_or_row = isset( $_REQUEST['and_or_row'] )
? $_REQUEST['and_or_row']
: array_fill(0, $col_cnt, '');
$and_or_col = isset( $_REQUEST['and_or_col'] )
? $_REQUEST['and_or_col']
: array_fill(0, $col_cnt, '');
// minimum width
$form_column_width = 12;
$col = max($col_cnt + $add_col, 0);
$row = max($rows + $add_row, 0);
// The tables list sent by a previously submitted form
if (!empty($TableList)) {
$cnt_table_list = count($TableList);
for ($x = 0; $x < $cnt_table_list; $x++) {
$tbl_names[urldecode($TableList[$x])] = ' selected="selected"';
}
} // end if
$columns = PMA_DBI_get_columns_full( $GLOBALS['db'] );
$tables = PMA_DBI_get_columns_full( $GLOBALS['db'] );
/**
* Prepares the form
*/
$tbl_result = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($db) . ';', null, PMA_DBI_QUERY_STORE);
$tbl_result_cnt = PMA_DBI_num_rows($tbl_result);
$i = 0;
$k = 0;
// The tables list gets from MySQL
while ($i < $tbl_result_cnt) {
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;
if (empty($tbl_names[$tbl]) && !empty($TableList)) {
$tbl_names[$tbl] = '';
} else {
$tbl_names[$tbl] = ' selected="selected"';
} // end if
// The fields list per selected tables
if ($tbl_names[$tbl] == ' selected="selected"') {
$fld[$k++] = PMA_backquote($tbl) . '.*';
while ($j < $fld_results_cnt) {
$fld[$k] = PMA_convert_display_charset($fld_results[$j]['Field']);
$fld[$k] = PMA_backquote($tbl) . '.' . PMA_backquote($fld[$k]);
// increase the width if necessary
if (strlen($fld[$k]) > $form_column_width) {
$form_column_width = strlen($fld[$k]);
} //end if
$k++;
$j++;
} // end while
} // end if
$i++;
} // end if
PMA_DBI_free_result($tbl_result);
// largest width found
$realwidth = $form_column_width . 'ex';
/**
* Displays the Query by example form
*/
function showColumnSelectCell( $columns, $column_number, $selected = '' )
{
?>
<td align="center">
<select name="Field[<?php echo $column_number; ?>]" size="1">
<option value=""></option>
<?php
foreach ( $columns as $column ) {
if ( $column === $selected ) {
$sel = ' selected="selected"';
} else {
$sel = '';
}
echo ' ';
echo '<option value="' . htmlspecialchars($column) . '"' . $sel . '>'
. htmlspecialchars($column) . '</option>' . "\n";
}
?>
</select>
</td>
<?php
}
?>
<form action="db_details_qbe.php" method="post">
<table>
<tr class="odd">
<th align="<?php echo $cell_align_right; ?>">
<?php echo $strField; ?>:
</th>
<?php
$z = 0;
for ($x = 0; $x < $col; $x++) {
if ( isset($ins_col[$x]) && $ins_col[$x] == 'on') {
showColumnSelectCe