/** * Looks for the presence of USE to possibly change current db * * @param string $buffer buffer to examine * @param string $db current db * @param bool $reload reload * * @return array (current or new db, whether to reload) * @access public */ function PMA_lookForUse($buffer, $db, $reload) { if (preg_match('@^[\\s]*USE[[:space:]]+([\\S]+)@i', $buffer, $match)) { $db = trim($match[1]); $db = trim($db, ';'); // for example, USE abc; // $db must not contain the escape characters generated by PMA_backquote() // ( used in PMA_buildSQL() as: PMA_backquote($db_name), and then called // in PMA_importRunQuery() which in turn calls PMA_lookForUse() ) $db = PMA_removeBackquote($db); $reload = true; } return array($db, $reload); }
/** * Does the exact opposite of PMA_backquote() * Unescapes backquotes ( from double backquotes to single backquotes) and * removes backquotes on both sides of the unescaped database name * * example: * <code> * echo PMA_removeBackquote('`owner``s db`'); // owner`s db * * </code> * * @param mixed $a_name the "backquoted" database, table or field name * or array of it * * @return mixed the "backquoted" database, table or field name * * @access public */ function PMA_removeBackquote($a_name) { if (is_array($a_name)) { foreach ($a_name as &$data) { $data = PMA_removeBackquote($data); } return $a_name; } // '0' is also empty for php :-( if (strlen($a_name) && $a_name !== '*') { $a_name = str_replace('``', '`', $a_name); // remove ` from beginning and end return substr($a_name, 1, strlen($a_name) - 2); } else { return $a_name; } }