本文整理汇总了PHP中PMA\libraries\Util::sqlAddSlashes方法的典型用法代码示例。如果您正苦于以下问题:PHP Util::sqlAddSlashes方法的具体用法?PHP Util::sqlAddSlashes怎么用?PHP Util::sqlAddSlashes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PMA\libraries\Util
的用法示例。
在下文中一共展示了Util::sqlAddSlashes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: PMA_getDbCollation
/**
* returns collation of given db
*
* @param string $db name of db
*
* @return string collation of $db
*/
function PMA_getDbCollation($db)
{
if ($GLOBALS['dbi']->isSystemSchema($db)) {
// We don't have to check the collation of the virtual
// information_schema database: We know it!
return 'utf8_general_ci';
}
if (!$GLOBALS['cfg']['Server']['DisableIS']) {
// this is slow with thousands of databases
$sql = 'SELECT DEFAULT_COLLATION_NAME FROM information_schema.SCHEMATA' . ' WHERE SCHEMA_NAME = \'' . Util::sqlAddSlashes($db) . '\' LIMIT 1';
return $GLOBALS['dbi']->fetchValue($sql);
} else {
$GLOBALS['dbi']->selectDb($db);
$return = $GLOBALS['dbi']->fetchValue('SELECT @@collation_database');
if ($db !== $GLOBALS['db']) {
$GLOBALS['dbi']->selectDb($GLOBALS['db']);
}
return $return;
}
}
示例2: saveToDb
/**
* Save recent/favorite tables into phpMyAdmin database.
*
* @return true|Message
*/
public function saveToDb()
{
$username = $GLOBALS['cfg']['Server']['user'];
$sql_query = " REPLACE INTO " . $this->_getPmaTable() . " (`username`, `tables`)" . " VALUES ('" . $username . "', '" . Util::sqlAddSlashes(json_encode($this->_tables)) . "')";
$success = $GLOBALS['dbi']->tryQuery($sql_query, $GLOBALS['controllink']);
if (!$success) {
$error_msg = '';
switch ($this->_tableType) {
case 'recent':
$error_msg = __('Could not save recent table!');
break;
case 'favorite':
$error_msg = __('Could not save favorite table!');
break;
}
$message = Message::error($error_msg);
$message->addMessage('<br /><br />');
$message->addMessage(Message::rawError($GLOBALS['dbi']->getError($GLOBALS['controllink'])));
return $message;
}
return true;
}
示例3: _getDataCellForNonNumericColumns
/**
* Get data cell for non numeric type fields
*
* @param string $column the relevant column in data row
* @param string $class the html class for column
* @param object $meta the meta-information about
* the field
* @param array $map the list of relations
* @param array $_url_params the parameters for generate
* url
* @param boolean $condition_field the column should highlighted
* or not
* @param object|string $transformation_plugin the name of transformation
* function
* @param string $default_function the default transformation
* function
* @param string $transform_options the transformation parameters
* @param boolean $is_field_truncated is data truncated due to
* LimitChars
* @param array $analyzed_sql_results the analyzed query
* @param integer &$dt_result the link id associated to
* the query which results
* have to be displayed
* @param integer $col_index the column index
*
* @return string $cell the prepared data cell, html content
*
* @access private
*
* @see _getTableBody()
*/
private function _getDataCellForNonNumericColumns($column, $class, $meta, $map, $_url_params, $condition_field, $transformation_plugin, $default_function, $transform_options, $is_field_truncated, $analyzed_sql_results, &$dt_result, $col_index)
{
$original_length = 0;
$is_analyse = $this->__get('is_analyse');
$field_flags = $GLOBALS['dbi']->fieldFlags($dt_result, $col_index);
$bIsText = gettype($transformation_plugin) === 'object' && strpos($transformation_plugin->getMIMEtype(), 'Text') === false;
// disable inline grid editing
// if binary fields are protected
// or transformation plugin is of non text type
// such as image
if (stristr($field_flags, self::BINARY_FIELD) && ($GLOBALS['cfg']['ProtectBinary'] === 'all' || $GLOBALS['cfg']['ProtectBinary'] === 'noblob' && !stristr($meta->type, self::BLOB_FIELD) || $GLOBALS['cfg']['ProtectBinary'] === 'blob' && stristr($meta->type, self::BLOB_FIELD)) || $bIsText) {
$class = str_replace('grid_edit', '', $class);
}
if (!isset($column) || is_null($column)) {
$cell = $this->_buildNullDisplay($class, $condition_field, $meta);
return $cell;
}
if ($column == '') {
$cell = $this->_buildEmptyDisplay($class, $condition_field, $meta);
return $cell;
}
// Cut all fields to $GLOBALS['cfg']['LimitChars']
// (unless it's a link-type transformation or binary)
if (!(gettype($transformation_plugin) === "object" && strpos($transformation_plugin->getName(), 'Link') !== false) && !stristr($field_flags, self::BINARY_FIELD)) {
list($is_field_truncated, $column, $original_length) = $this->_getPartialText($column);
}
$formatted = false;
if (isset($meta->_type) && $meta->_type === MYSQLI_TYPE_BIT) {
$column = Util::printableBitValue($column, $meta->length);
// some results of PROCEDURE ANALYSE() are reported as
// being BINARY but they are quite readable,
// so don't treat them as BINARY
} elseif (stristr($field_flags, self::BINARY_FIELD) && !(isset($is_analyse) && $is_analyse)) {
// we show the BINARY or BLOB message and field's size
// (or maybe use a transformation)
$binary_or_blob = self::BLOB_FIELD;
if ($meta->type === self::STRING_FIELD) {
$binary_or_blob = self::BINARY_FIELD;
}
$column = $this->_handleNonPrintableContents($binary_or_blob, $column, $transformation_plugin, $transform_options, $default_function, $meta, $_url_params, $is_field_truncated);
$class = $this->_addClass($class, $condition_field, $meta, '', $is_field_truncated, $transformation_plugin, $default_function);
$result = strip_tags($column);
// disable inline grid editing
// if binary or blob data is not shown
if (stristr($result, $binary_or_blob)) {
$class = str_replace('grid_edit', '', $class);
}
$formatted = true;
}
if ($formatted) {
$cell = $this->_buildValueDisplay($class, $condition_field, $column);
return $cell;
}
// transform functions may enable no-wrapping:
$function_nowrap = 'applyTransformationNoWrap';
$bool_nowrap = $default_function != $transformation_plugin && function_exists($transformation_plugin->{$function_nowrap}()) ? $transformation_plugin->{$function_nowrap}($transform_options) : false;
// do not wrap if date field type
$nowrap = preg_match('@DATE|TIME@i', $meta->type) || $bool_nowrap ? ' nowrap' : '';
$where_comparison = ' = \'' . Util::sqlAddSlashes($column) . '\'';
$cell = $this->_getRowData($class, $condition_field, $analyzed_sql_results, $meta, $map, $column, $transformation_plugin, $default_function, $nowrap, $where_comparison, $transform_options, $is_field_truncated, $original_length);
return $cell;
}
示例4: _getWhereClause
/**
* Return the where clause for query generation based on the inputs provided.
*
* @param mixed $criteriaValues Search criteria input
* @param string $names Name of the column on which search is submitted
* @param string $types Type of the field
* @param string $func_type Search function/operator
* @param bool $unaryFlag Whether operator unary or not
* @param bool $geom_func Whether geometry functions should be applied
*
* @return string generated where clause.
*/
private function _getWhereClause($criteriaValues, $names, $types, $func_type, $unaryFlag, $geom_func = null)
{
// If geometry function is set
if (!empty($geom_func)) {
return $this->_getGeomWhereClause($criteriaValues, $names, $func_type, $types, $geom_func);
}
$backquoted_name = Util::backquote($names);
$where = '';
if ($unaryFlag) {
$where = $backquoted_name . ' ' . $func_type;
} elseif (strncasecmp($types, 'enum', 4) == 0 && !empty($criteriaValues)) {
$where = $backquoted_name;
$where .= $this->_getEnumWhereClause($criteriaValues, $func_type);
} elseif ($criteriaValues != '') {
// For these types we quote the value. Even if it's another type
// (like INT), for a LIKE we always quote the value. MySQL converts
// strings to numbers and numbers to strings as necessary
// during the comparison
if (preg_match('@char|binary|blob|text|set|date|time|year@i', $types) || mb_strpos(' ' . $func_type, 'LIKE')) {
$quot = '\'';
} else {
$quot = '';
}
// LIKE %...%
if ($func_type == 'LIKE %...%') {
$func_type = 'LIKE';
$criteriaValues = '%' . $criteriaValues . '%';
}
if ($func_type == 'REGEXP ^...$') {
$func_type = 'REGEXP';
$criteriaValues = '^' . $criteriaValues . '$';
}
if ('IN (...)' != $func_type && 'NOT IN (...)' != $func_type && 'BETWEEN' != $func_type && 'NOT BETWEEN' != $func_type) {
if ($func_type == 'LIKE %...%' || $func_type == 'LIKE') {
$where = $backquoted_name . ' ' . $func_type . ' ' . $quot . Util::sqlAddSlashes($criteriaValues, true) . $quot;
} else {
$where = $backquoted_name . ' ' . $func_type . ' ' . $quot . Util::sqlAddSlashes($criteriaValues) . $quot;
}
return $where;
}
$func_type = str_replace(' (...)', '', $func_type);
//Don't explode if this is already an array
//(Case for (NOT) IN/BETWEEN.)
if (is_array($criteriaValues)) {
$values = $criteriaValues;
} else {
$values = explode(',', $criteriaValues);
}
// quote values one by one
$emptyKey = false;
foreach ($values as $key => &$value) {
if ('' === $value) {
$emptyKey = $key;
$value = 'NULL';
continue;
}
$value = $quot . Util::sqlAddSlashes(trim($value)) . $quot;
}
if ('BETWEEN' == $func_type || 'NOT BETWEEN' == $func_type) {
$where = $backquoted_name . ' ' . $func_type . ' ' . (isset($values[0]) ? $values[0] : '') . ' AND ' . (isset($values[1]) ? $values[1] : '');
} else {
//[NOT] IN
if (false !== $emptyKey) {
unset($values[$emptyKey]);
}
$wheres = array();
if (!empty($values)) {
$wheres[] = $backquoted_name . ' ' . $func_type . ' (' . implode(',', $values) . ')';
}
if (false !== $emptyKey) {
$wheres[] = $backquoted_name . ' IS NULL';
}
$where = implode(' OR ', $wheres);
if (1 < count($wheres)) {
$where = '(' . $where . ')';
}
}
}
// end if
return $where;
}
示例5: setValueAction
/**
* Handle the AJAX request for setting value for a single variable
*
* @return void
*/
public function setValueAction()
{
$value = $_REQUEST['varValue'];
$matches = array();
if (isset($this->variable_doc_links[$_REQUEST['varName']][3]) && $this->variable_doc_links[$_REQUEST['varName']][3] == 'byte' && preg_match('/^\\s*(\\d+(\\.\\d+)?)\\s*(mb|kb|mib|kib|gb|gib)\\s*$/i', $value, $matches)) {
$exp = array('kb' => 1, 'kib' => 1, 'mb' => 2, 'mib' => 2, 'gb' => 3, 'gib' => 3);
$value = floatval($matches[1]) * Util::pow(1024, $exp[mb_strtolower($matches[3])]);
} else {
$value = Util::sqlAddSlashes($value);
}
if (!is_numeric($value)) {
$value = "'" . $value . "'";
}
if (!preg_match("/[^a-zA-Z0-9_]+/", $_REQUEST['varName']) && $this->dbi->query('SET GLOBAL ' . $_REQUEST['varName'] . ' = ' . $value)) {
// Some values are rounded down etc.
$varValue = $this->dbi->fetchSingleRow('SHOW GLOBAL VARIABLES WHERE Variable_name="' . Util::sqlAddSlashes($_REQUEST['varName']) . '";', 'NUM');
$this->response->addJSON('variable', htmlspecialchars($this->_formatVariable($_REQUEST['varName'], $varValue[1])));
} else {
$this->response->setRequestStatus(false);
$this->response->addJSON('error', __('Setting variable failed'));
}
}
示例6: PMA_getHTMLforEditingPage
/**
* Get HTML for editing page central columns
*
* @param array $selected_fld Array containing the selected fields
* @param string $selected_db String containing the name of database
*
* @return string HTML for complete editing page for central columns
*/
function PMA_getHTMLforEditingPage($selected_fld, $selected_db)
{
$html = '<form id="multi_edit_central_columns">';
$header_cells = array(__('Name'), __('Type'), __('Length/Values'), __('Default'), __('Collation'), __('Attributes'), __('Null'), __('A_I'));
$html .= PMA_getCentralColumnsEditTableHeader($header_cells);
$selected_fld_safe = array();
foreach ($selected_fld as $key) {
$selected_fld_safe[] = Util::sqlAddSlashes($key);
}
$columns_list = implode("','", $selected_fld_safe);
$columns_list = "'" . $columns_list . "'";
$list_detail_cols = PMA_findExistingColNames($selected_db, $columns_list, true);
$odd_row = false;
$row_num = 0;
foreach ($list_detail_cols as $row) {
$tableHtmlRow = PMA_getHTMLforCentralColumnsEditTableRow($row, $odd_row, $row_num);
$html .= $tableHtmlRow;
$odd_row = !$odd_row;
$row_num++;
}
$html .= '</table>';
$html .= PMA_getCentralColumnsEditTableFooter();
$html .= '</form>';
return $html;
}
示例7: getNavigationHidingData
/**
* Gets the count of hidden elements for each database
*
* @return array array containing the count of hidden elements for each database
*/
public function getNavigationHidingData()
{
$cfgRelation = PMA_getRelationsParam();
if ($cfgRelation['navwork']) {
$navTable = Util::backquote($cfgRelation['db']) . "." . Util::backquote($cfgRelation['navigationhiding']);
$sqlQuery = "SELECT `db_name`, COUNT(*) AS `count` FROM " . $navTable . " WHERE `username`='" . Util::sqlAddSlashes($GLOBALS['cfg']['Server']['user']) . "'" . " GROUP BY `db_name`";
$counts = $GLOBALS['dbi']->fetchResult($sqlQuery, 'db_name', 'count', $GLOBALS['controllink']);
return $counts;
}
return null;
}
示例8: getTablesWhenOpen
/**
* Gets the list of tables in the current db, taking into account
* that they might be "in use"
*
* @param string $db database name
* @param object $db_info_result result set
*
* @return array $tables list of tables
*
*/
public static function getTablesWhenOpen($db, $db_info_result)
{
$sot_cache = $tables = array();
while ($tmp = $GLOBALS['dbi']->fetchAssoc($db_info_result)) {
// if in use, memorize table name
if ($tmp['In_use'] > 0) {
$sot_cache[$tmp['Table']] = true;
}
}
$GLOBALS['dbi']->freeResult($db_info_result);
// is there at least one "in use" table?
if (isset($sot_cache)) {
$tblGroupSql = "";
$whereAdded = false;
if (PMA_isValid($_REQUEST['tbl_group'])) {
$group = Util::escapeMysqlWildcards($_REQUEST['tbl_group']);
$groupWithSeparator = Util::escapeMysqlWildcards($_REQUEST['tbl_group'] . $GLOBALS['cfg']['NavigationTreeTableSeparator']);
$tblGroupSql .= " WHERE (" . Util::backquote('Tables_in_' . $db) . " LIKE '" . $groupWithSeparator . "%'" . " OR " . Util::backquote('Tables_in_' . $db) . " LIKE '" . $group . "')";
$whereAdded = true;
}
if (PMA_isValid($_REQUEST['tbl_type'], array('table', 'view'))) {
$tblGroupSql .= $whereAdded ? " AND" : " WHERE";
if ($_REQUEST['tbl_type'] == 'view') {
$tblGroupSql .= " `Table_type` != 'BASE TABLE'";
} else {
$tblGroupSql .= " `Table_type` = 'BASE TABLE'";
}
}
$db_info_result = $GLOBALS['dbi']->query('SHOW FULL TABLES FROM ' . Util::backquote($db) . $tblGroupSql, null, DatabaseInterface::QUERY_STORE);
unset($tblGroupSql, $whereAdded);
if ($db_info_result && $GLOBALS['dbi']->numRows($db_info_result) > 0) {
while ($tmp = $GLOBALS['dbi']->fetchRow($db_info_result)) {
if (!isset($sot_cache[$tmp[0]])) {
$sts_result = $GLOBALS['dbi']->query("SHOW TABLE STATUS FROM " . Util::backquote($db) . " LIKE '" . Util::sqlAddSlashes($tmp[0], true) . "';");
$sts_tmp = $GLOBALS['dbi']->fetchAssoc($sts_result);
$GLOBALS['dbi']->freeResult($sts_result);
unset($sts_result);
$tableArray = $GLOBALS['dbi']->copyTableProperties(array($sts_tmp), $db);
$tables[$sts_tmp['Name']] = $tableArray[0];
} else {
// table in use
$tables[$tmp[0]] = array('TABLE_NAME' => $tmp[0], 'ENGINE' => '', 'TABLE_TYPE' => '', 'TABLE_ROWS' => 0);
}
}
// end while
if ($GLOBALS['cfg']['NaturalOrder']) {
uksort($tables, 'strnatcasecmp');
}
} elseif ($db_info_result) {
$GLOBALS['dbi']->freeResult($db_info_result);
}
unset($sot_cache);
}
return $tables;
}
示例9: _getNavigationDbPos
/**
* Returns the database position for the page selector
*
* @return int
*/
private function _getNavigationDbPos()
{
$retval = 0;
if (empty($GLOBALS['db'])) {
return $retval;
}
/*
* @todo describe a scenario where this code is executed
*/
if (!$GLOBALS['cfg']['Server']['DisableIS']) {
$query = "SELECT (COUNT(DB_first_level) DIV %d) * %d ";
$query .= "from ( ";
$query .= " SELECT distinct SUBSTRING_INDEX(SCHEMA_NAME, ";
$query .= " '{$GLOBALS['cfg']['NavigationTreeDbSeparator']}', 1) ";
$query .= " DB_first_level ";
$query .= " FROM INFORMATION_SCHEMA.SCHEMATA ";
$query .= " WHERE `SCHEMA_NAME` < '%s' ";
$query .= ") t ";
$retval = $GLOBALS['dbi']->fetchValue(sprintf($query, (int) $GLOBALS['cfg']['FirstLevelNavigationItems'], (int) $GLOBALS['cfg']['FirstLevelNavigationItems'], Util::sqlAddSlashes($GLOBALS['db'])));
return $retval;
}
$prefixMap = array();
if ($GLOBALS['dbs_to_test'] === false) {
$handle = $GLOBALS['dbi']->tryQuery("SHOW DATABASES");
if ($handle !== false) {
while ($arr = $GLOBALS['dbi']->fetchArray($handle)) {
if (strcasecmp($arr[0], $GLOBALS['db']) >= 0) {
break;
}
$prefix = strstr($arr[0], $GLOBALS['cfg']['NavigationTreeDbSeparator'], true);
if ($prefix === false) {
$prefix = $arr[0];
}
$prefixMap[$prefix] = 1;
}
}
} else {
$databases = array();
foreach ($GLOBALS['dbs_to_test'] as $db) {
$query = "SHOW DATABASES LIKE '" . $db . "'";
$handle = $GLOBALS['dbi']->tryQuery($query);
if ($handle === false) {
continue;
}
while ($arr = $GLOBALS['dbi']->fetchArray($handle)) {
$databases[] = $arr[0];
}
}
sort($databases);
foreach ($databases as $database) {
if (strcasecmp($database, $GLOBALS['db']) >= 0) {
break;
}
$prefix = strstr($database, $GLOBALS['cfg']['NavigationTreeDbSeparator'], true);
if ($prefix === false) {
$prefix = $database;
}
$prefixMap[$prefix] = 1;
}
}
$navItems = (int) $GLOBALS['cfg']['FirstLevelNavigationItems'];
$retval = floor(count($prefixMap) / $navItems) * $navItems;
return $retval;
}
示例10: getItemUnhideDialog
/**
* Returns HTML for the dialog to show hidden navigation items.
*
* @param string $dbName database name
* @param string $itemType type of the items to include
* @param string $tableName table name
*
* @return string HTML for the dialog to show hidden navigation items
*/
public function getItemUnhideDialog($dbName, $itemType = null, $tableName = null)
{
$html = '<form method="post" action="navigation.php" class="ajax">';
$html .= '<fieldset>';
$html .= URL::getHiddenInputs($dbName, $tableName);
$navTable = Util::backquote($GLOBALS['cfgRelation']['db']) . "." . Util::backquote($GLOBALS['cfgRelation']['navigationhiding']);
$sqlQuery = "SELECT `item_name`, `item_type` FROM " . $navTable . " WHERE `username`='" . Util::sqlAddSlashes($GLOBALS['cfg']['Server']['user']) . "'" . " AND `db_name`='" . Util::sqlAddSlashes($dbName) . "'" . " AND `table_name`='" . (!empty($tableName) ? Util::sqlAddSlashes($tableName) : '') . "'";
$result = PMA_queryAsControlUser($sqlQuery, false);
$hidden = array();
if ($result) {
while ($row = $GLOBALS['dbi']->fetchArray($result)) {
$type = $row['item_type'];
if (!isset($hidden[$type])) {
$hidden[$type] = array();
}
$hidden[$type][] = $row['item_name'];
}
}
$GLOBALS['dbi']->freeResult($result);
$typeMap = array('group' => __('Groups:'), 'event' => __('Events:'), 'function' => __('Functions:'), 'procedure' => __('Procedures:'), 'table' => __('Tables:'), 'view' => __('Views:'));
if (empty($tableName)) {
$first = true;
foreach ($typeMap as $t => $lable) {
if ((empty($itemType) || $itemType == $t) && isset($hidden[$t])) {
$html .= (!$first ? '<br/>' : '') . '<strong>' . $lable . '</strong>';
$html .= '<table width="100%"><tbody>';
$odd = true;
foreach ($hidden[$t] as $hiddenItem) {
$html .= '<tr class="' . ($odd ? 'odd' : 'even') . '">';
$html .= '<td>' . htmlspecialchars($hiddenItem) . '</td>';
$html .= '<td style="width:80px"><a href="navigation.php' . URL::getCommon() . '&unhideNavItem=true' . '&itemType=' . urlencode($t) . '&itemName=' . urlencode($hiddenItem) . '&dbName=' . urlencode($dbName) . '"' . ' class="unhideNavItem ajax">' . Util::getIcon('show.png', __('Show')) . '</a></td>';
$odd = !$odd;
}
$html .= '</tbody></table>';
$first = false;
}
}
}
$html .= '</fieldset>';
$html .= '</form>';
return $html;
}
示例11: PMA_buildSQL
//.........这里部分代码省略.........
*/
$tempSQLStr = "";
$col_count = 0;
$num_tables = count($tables);
for ($i = 0; $i < $num_tables; ++$i) {
$num_cols = count($tables[$i][COL_NAMES]);
$num_rows = count($tables[$i][ROWS]);
$tempSQLStr = "INSERT INTO " . PMA\libraries\Util::backquote($db_name) . '.' . PMA\libraries\Util::backquote($tables[$i][TBL_NAME]) . " (";
for ($m = 0; $m < $num_cols; ++$m) {
$tempSQLStr .= PMA\libraries\Util::backquote($tables[$i][COL_NAMES][$m]);
if ($m != $num_cols - 1) {
$tempSQLStr .= ", ";
}
}
$tempSQLStr .= ") VALUES ";
for ($j = 0; $j < $num_rows; ++$j) {
$tempSQLStr .= "(";
for ($k = 0; $k < $num_cols; ++$k) {
// If fully formatted SQL, no need to enclose
// with apostrophes, add slashes etc.
if ($analyses != null && isset($analyses[$i][FORMATTEDSQL][$col_count]) && $analyses[$i][FORMATTEDSQL][$col_count] == true) {
$tempSQLStr .= (string) $tables[$i][ROWS][$j][$k];
} else {
if ($analyses != null) {
$is_varchar = $analyses[$i][TYPES][$col_count] === VARCHAR;
} else {
$is_varchar = !is_numeric($tables[$i][ROWS][$j][$k]);
}
/* Don't put quotes around NULL fields */
if (!strcmp($tables[$i][ROWS][$j][$k], 'NULL')) {
$is_varchar = false;
}
$tempSQLStr .= $is_varchar ? "'" : "";
$tempSQLStr .= PMA\libraries\Util::sqlAddSlashes((string) $tables[$i][ROWS][$j][$k]);
$tempSQLStr .= $is_varchar ? "'" : "";
}
if ($k != $num_cols - 1) {
$tempSQLStr .= ", ";
}
if ($col_count == $num_cols - 1) {
$col_count = 0;
} else {
$col_count++;
}
/* Delete the cell after we are done with it */
unset($tables[$i][ROWS][$j][$k]);
}
$tempSQLStr .= ")";
if ($j != $num_rows - 1) {
$tempSQLStr .= ",\n ";
}
$col_count = 0;
/* Delete the row after we are done with it */
unset($tables[$i][ROWS][$j]);
}
$tempSQLStr .= ";";
/**
* Each SQL statement is executed immediately
* after it is formed so that we don't have
* to store them in a (possibly large) buffer
*/
PMA_importRunQuery($tempSQLStr, $tempSQLStr);
}
/* No longer needed */
unset($tempSQLStr);
/**
示例12: getData
/**
* Returns the names of children of type $type present inside this container
* This method is overridden by the PMA\libraries\navigation\nodes\NodeDatabase
* and PMA\libraries\navigation\nodes\NodeTable classes
*
* @param string $type The type of item we are looking for
* ('tables', 'views', etc)
* @param int $pos The offset of the list within the results
* @param string $searchClause A string used to filter the results of the query
*
* @return array
*/
public function getData($type, $pos, $searchClause = '')
{
$maxItems = $GLOBALS['cfg']['MaxNavigationItems'];
$retval = array();
$db = $this->realParent()->real_name;
$table = $this->real_name;
switch ($type) {
case 'columns':
if (!$GLOBALS['cfg']['Server']['DisableIS']) {
$db = Util::sqlAddSlashes($db);
$table = Util::sqlAddSlashes($table);
$query = "SELECT `COLUMN_NAME` AS `name` ";
$query .= "FROM `INFORMATION_SCHEMA`.`COLUMNS` ";
$query .= "WHERE `TABLE_NAME`='{$table}' ";
$query .= "AND `TABLE_SCHEMA`='{$db}' ";
$query .= "ORDER BY `COLUMN_NAME` ASC ";
$query .= "LIMIT " . intval($pos) . ", {$maxItems}";
$retval = $GLOBALS['dbi']->fetchResult($query);
break;
}
$db = Util::backquote($db);
$table = Util::backquote($table);
$query = "SHOW COLUMNS FROM {$table} FROM {$db}";
$handle = $GLOBALS['dbi']->tryQuery($query);
if ($handle === false) {
break;
}
$count = 0;
if ($GLOBALS['dbi']->dataSeek($handle, $pos)) {
while ($arr = $GLOBALS['dbi']->fetchArray($handle)) {
if ($count < $maxItems) {
$retval[] = $arr['Field'];
$count++;
} else {
break;
}
}
}
break;
case 'indexes':
$db = Util::backquote($db);
$table = Util::backquote($table);
$query = "SHOW INDEXES FROM {$table} FROM {$db}";
$handle = $GLOBALS['dbi']->tryQuery($query);
if ($handle === false) {
break;
}
$count = 0;
while ($arr = $GLOBALS['dbi']->fetchArray($handle)) {
if (in_array($arr['Key_name'], $retval)) {
continue;
}
if ($pos <= 0 && $count < $maxItems) {
$retval[] = $arr['Key_name'];
$count++;
}
$pos--;
}
break;
case 'triggers':
if (!$GLOBALS['cfg']['Server']['DisableIS']) {
$db = Util::sqlAddSlashes($db);
$table = Util::sqlAddSlashes($table);
$query = "SELECT `TRIGGER_NAME` AS `name` ";
$query .= "FROM `INFORMATION_SCHEMA`.`TRIGGERS` ";
$query .= "WHERE `EVENT_OBJECT_SCHEMA` " . Util::getCollateForIS() . "='{$db}' ";
$query .= "AND `EVENT_OBJECT_TABLE` " . Util::getCollateForIS() . "='{$table}' ";
$query .= "ORDER BY `TRIGGER_NAME` ASC ";
$query .= "LIMIT " . intval($pos) . ", {$maxItems}";
$retval = $GLOBALS['dbi']->fetchResult($query);
break;
}
$db = Util::backquote($db);
$table = Util::sqlAddSlashes($table);
$query = "SHOW TRIGGERS FROM {$db} WHERE `Table` = '{$table}'";
$handle = $GLOBALS['dbi']->tryQuery($query);
if ($handle === false) {
break;
}
$count = 0;
if ($GLOBALS['dbi']->dataSeek($handle, $pos)) {
while ($arr = $GLOBALS['dbi']->fetchArray($handle)) {
if ($count < $maxItems) {
$retval[] = $arr['Trigger'];
$count++;
} else {
break;
}
//.........这里部分代码省略.........
示例13: doImport
/**
* Handles the whole import logic
*
* @return void
*/
public function doImport()
{
global $finished, $import_file, $compression, $charset_conversion, $table;
global $ldi_local_option, $ldi_replace, $ldi_ignore, $ldi_terminated, $ldi_enclosed, $ldi_escaped, $ldi_new_line, $skip_queries, $ldi_columns;
if ($import_file == 'none' || $compression != 'none' || $charset_conversion) {
// We handle only some kind of data!
$GLOBALS['message'] = PMA\libraries\Message::error(__('This plugin does not support compressed imports!'));
$GLOBALS['error'] = true;
return;
}
$sql = 'LOAD DATA';
if (isset($ldi_local_option)) {
$sql .= ' LOCAL';
}
$sql .= ' INFILE \'' . PMA\libraries\Util::sqlAddSlashes($import_file) . '\'';
if (isset($ldi_replace)) {
$sql .= ' REPLACE';
} elseif (isset($ldi_ignore)) {
$sql .= ' IGNORE';
}
$sql .= ' INTO TABLE ' . PMA\libraries\Util::backquote($table);
if (strlen($ldi_terminated) > 0) {
$sql .= ' FIELDS TERMINATED BY \'' . $ldi_terminated . '\'';
}
if (strlen($ldi_enclosed) > 0) {
$sql .= ' ENCLOSED BY \'' . PMA\libraries\Util::sqlAddSlashes($ldi_enclosed) . '\'';
}
if (strlen($ldi_escaped) > 0) {
$sql .= ' ESCAPED BY \'' . PMA\libraries\Util::sqlAddSlashes($ldi_escaped) . '\'';
}
if (strlen($ldi_new_line) > 0) {
if ($ldi_new_line == 'auto') {
$ldi_new_line = PMA\libraries\Util::whichCrlf() == "\n" ? '\\n' : '\\r\\n';
}
$sql .= ' LINES TERMINATED BY \'' . $ldi_new_line . '\'';
}
if ($skip_queries > 0) {
$sql .= ' IGNORE ' . $skip_queries . ' LINES';
$skip_queries = 0;
}
if (strlen($ldi_columns) > 0) {
$sql .= ' (';
$tmp = preg_split('/,( ?)/', $ldi_columns);
$cnt_tmp = count($tmp);
for ($i = 0; $i < $cnt_tmp; $i++) {
if ($i > 0) {
$sql .= ', ';
}
/* Trim also `, if user already included backquoted fields */
$sql .= PMA\libraries\Util::backquote(trim($tmp[$i], " \t\r\n\v`"));
}
// end for
$sql .= ')';
}
PMA_importRunQuery($sql, $sql);
PMA_importRunQuery();
$finished = true;
}
示例14: get
/**
* Retrieve a specific bookmark
*
* @param string $db the current database name
* @param mixed $id an identifier of the bookmark to get
* @param string $id_field which field to look up the identifier
* @param boolean $action_bookmark_all true: get all bookmarks regardless
* of the owning user
* @param boolean $exact_user_match whether to ignore bookmarks with no user
*
* @return Bookmark the bookmark
*
* @access public
*
* @global resource $controllink the controluser db connection handle
*
*/
public static function get($db, $id, $id_field = 'id', $action_bookmark_all = false, $exact_user_match = false)
{
global $controllink;
$cfgBookmark = self::getParams();
if (empty($cfgBookmark)) {
return null;
}
$query = "SELECT * FROM " . Util::backquote($cfgBookmark['db']) . "." . Util::backquote($cfgBookmark['table']) . " WHERE dbase = '" . Util::sqlAddSlashes($db) . "'";
if (!$action_bookmark_all) {
$query .= " AND (user = '" . Util::sqlAddSlashes($cfgBookmark['user']) . "'";
if (!$exact_user_match) {
$query .= " OR user = ''";
}
$query .= ")";
}
$query .= " AND " . Util::backquote($id_field) . " = " . Util::sqlAddSlashes($id) . " LIMIT 1";
$result = $GLOBALS['dbi']->fetchSingleRow($query, 'ASSOC', $controllink);
if (!empty($result)) {
$bookmark = new Bookmark();
$bookmark->_id = $result['id'];
$bookmark->_database = $result['dbase'];
$bookmark->_user = $result['user'];
$bookmark->_label = $result['label'];
$bookmark->_query = $result['query'];
return $bookmark;
}
return null;
}
示例15: getColumnGenerationExpression
/**
* Returns the generation expression for virtual columns
*
* @param string $column name of the column
*
* @return array|boolean associative array of column name and their expressions
* or false on failure
*/
public function getColumnGenerationExpression($column = null)
{
$serverType = Util::getServerType();
if ($serverType == 'MySQL' && PMA_MYSQL_INT_VERSION > 50705 && !$GLOBALS['cfg']['Server']['DisableIS']) {
$sql = "SELECT\n `COLUMN_NAME` AS `Field`,\n `GENERATION_EXPRESSION` AS `Expression`\n FROM\n `information_schema`.`COLUMNS`\n WHERE\n `TABLE_SCHEMA` = '" . Util::sqlAddSlashes($this->_db_name) . "'\n AND `TABLE_NAME` = '" . Util::sqlAddSlashes($this->_name) . "'";
if ($column != null) {
$sql .= " AND `COLUMN_NAME` = '" . Util::sqlAddSlashes($column) . "'";
}
$columns = $this->_dbi->fetchResult($sql, 'Field', 'Expression');
return $columns;
}
$createTable = $this->showCreate();
if (!$createTable) {
return false;
}
$parser = new Parser($createTable);
/**
* @var \SqlParser\Statements\CreateStatement $stmt
*/
$stmt = $parser->statements[0];
$fields = Table::getFields($stmt);
if ($column != null) {
$expression = isset($fields[$column]['expr']) ? substr($fields[$column]['expr'], 1, -1) : '';
return array($column => $expression);
}
$ret = array();
foreach ($fields as $field => $options) {
if (isset($options['expr'])) {
$ret[$field] = substr($options['expr'], 1, -1);
}
}
return $ret;
}