本文整理汇总了PHP中SqlParser\Context::setMode方法的典型用法代码示例。如果您正苦于以下问题:PHP Context::setMode方法的具体用法?PHP Context::setMode怎么用?PHP Context::setMode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SqlParser\Context
的用法示例。
在下文中一共展示了Context::setMode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testEscape
public function testEscape()
{
Context::setMode('ANSI_QUOTES');
$this->assertEquals('"test"', Context::escape('test'));
Context::setMode();
$this->assertEquals('`test`', Context::escape('test'));
$this->assertEquals(array('`a`', '`b`'), Context::escape(array('a', 'b')));
}
示例2: moveCopy
/**
* Copies or renames table
*
* @param string $source_db source database
* @param string $source_table source table
* @param string $target_db target database
* @param string $target_table target table
* @param string $what what to be moved or copied (data, dataonly)
* @param bool $move whether to move
* @param string $mode mode
*
* @return bool true if success, false otherwise
*/
public static function moveCopy($source_db, $source_table, $target_db, $target_table, $what, $move, $mode)
{
global $err_url;
// Try moving the tables directly, using native `RENAME` statement.
if ($move && $what == 'data') {
$tbl = new Table($source_table, $source_db);
if ($tbl->rename($target_table, $target_db)) {
$GLOBALS['message'] = $tbl->getLastMessage();
return true;
}
}
// Setting required export settings.
$GLOBALS['sql_backquotes'] = 1;
$GLOBALS['asfile'] = 1;
// Ensuring the target database is valid.
if (!$GLOBALS['pma']->databases->exists($source_db, $target_db)) {
if (!$GLOBALS['pma']->databases->exists($source_db)) {
$GLOBALS['message'] = Message::rawError(sprintf(__('Source database `%s` was not found!'), htmlspecialchars($source_db)));
}
if (!$GLOBALS['pma']->databases->exists($target_db)) {
$GLOBALS['message'] = Message::rawError(sprintf(__('Target database `%s` was not found!'), htmlspecialchars($target_db)));
}
return false;
}
/**
* The full name of source table, quoted.
* @var string $source
*/
$source = Util::backquote($source_db) . '.' . Util::backquote($source_table);
// If the target database is not specified, the operation is taking
// place in the same database.
if (!isset($target_db) || !mb_strlen($target_db)) {
$target_db = $source_db;
}
// Selecting the database could avoid some problems with replicated
// databases, when moving table from replicated one to not replicated one.
$GLOBALS['dbi']->selectDb($target_db);
/**
* The full name of target table, quoted.
* @var string $target
*/
$target = Util::backquote($target_db) . '.' . Util::backquote($target_table);
// No table is created when this is a data-only operation.
if ($what != 'dataonly') {
include_once "libraries/plugin_interface.lib.php";
/**
* Instance used for exporting the current structure of the table.
*
* @var \PMA\libraries\plugins\export\ExportSql
*/
$export_sql_plugin = PMA_getPlugin("export", "sql", 'libraries/plugins/export/', array('export_type' => 'table', 'single_table' => false));
$no_constraints_comments = true;
$GLOBALS['sql_constraints_query'] = '';
// set the value of global sql_auto_increment variable
if (isset($_POST['sql_auto_increment'])) {
$GLOBALS['sql_auto_increment'] = $_POST['sql_auto_increment'];
}
/**
* The old structure of the table..
* @var string $sql_structure
*/
$sql_structure = $export_sql_plugin->getTableDef($source_db, $source_table, "\n", $err_url, false, false);
unset($no_constraints_comments);
// -----------------------------------------------------------------
// Phase 0: Preparing structures used.
/**
* The destination where the table is moved or copied to.
* @var Expression
*/
$destination = new Expression($target_db, $target_table, '');
// Find server's SQL mode so the builder can generate correct
// queries.
// One of the options that alters the behaviour is `ANSI_QUOTES`.
Context::setMode($GLOBALS['dbi']->fetchValue("SELECT @@sql_mode"));
// -----------------------------------------------------------------
// Phase 1: Dropping existent element of the same name (if exists
// and required).
if (isset($_REQUEST['drop_if_exists']) && $_REQUEST['drop_if_exists'] == 'true') {
/**
* Drop statement used for building the query.
* @var DropStatement $statement
*/
$statement = new DropStatement();
$tbl = new Table($target_db, $target_table);
$statement->options = new OptionsArray(array($tbl->isView() ? 'VIEW' : 'TABLE', 'IF EXISTS'));
$statement->fields = array($destination);
// Building the query.
//.........这里部分代码省略.........