PMA\libraries\Util::backquoteCompat PHP Method

backquoteCompat() public static method

in compatibility mode example: echo backquoteCompat('owners db'); // owners db
public static backquoteCompat ( mixed $a_name, string $compatibility = 'MSSQL', boolean $do_it = true ) : mixed
$a_name mixed the database, table or field name to "backquote" or array of it
$compatibility string string compatibility mode (used by dump functions)
$do_it boolean a flag to bypass this function (used by dump functions)
return mixed the "backquoted" database, table or field name
    public static function backquoteCompat($a_name, $compatibility = 'MSSQL', $do_it = true)
    {
        if (is_array($a_name)) {
            foreach ($a_name as &$data) {
                $data = self::backquoteCompat($data, $compatibility, $do_it);
            }
            return $a_name;
        }
        if (!$do_it) {
            if (!Context::isKeyword($a_name)) {
                return $a_name;
            }
        }
        // @todo add more compatibility cases (ORACLE for example)
        switch ($compatibility) {
            case 'MSSQL':
                $quote = '"';
                break;
            default:
                $quote = "`";
                break;
        }
        // '0' is also empty for php :-(
        if (strlen($a_name) > 0 && $a_name !== '*') {
            return $quote . $a_name . $quote;
        } else {
            return $a_name;
        }
    }

Usage Example

Esempio n. 1
0
 /**
  * Generate comment
  *
  * @param string $crlf          Carriage return character
  * @param string $sql_statement SQL statement
  * @param string $comment1      Comment for dumped table
  * @param string $comment2      Comment for current table
  * @param string $table_alias   Table alias
  * @param string $compat        Compatibility mode
  *
  * @return string
  */
 protected function generateComment($crlf, $sql_statement, $comment1, $comment2, $table_alias, $compat)
 {
     if (!isset($sql_statement)) {
         if (isset($GLOBALS['no_constraints_comments'])) {
             $sql_statement = '';
         } else {
             $sql_statement = $crlf . $this->_exportComment() . $this->_exportComment($comment1) . $this->_exportComment();
         }
     }
     // comments for current table
     if (!isset($GLOBALS['no_constraints_comments'])) {
         $sql_statement .= $crlf . $this->_exportComment() . $this->_exportComment($comment2 . ' ' . Util::backquoteCompat($table_alias, $compat, isset($GLOBALS['sql_backquotes']))) . $this->_exportComment();
     }
     return $sql_statement;
 }
Util