init web ems all
This commit is contained in:
454
phpMyAdmin/libraries/classes/Dbi/DbiDummy.php
Executable file
454
phpMyAdmin/libraries/classes/Dbi/DbiDummy.php
Executable file
@@ -0,0 +1,454 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Fake database driver for testing purposes
|
||||
*
|
||||
* It has hardcoded results for given queries what makes easy to use it
|
||||
* in testsuite. Feel free to include other queries which your test will
|
||||
* need.
|
||||
*
|
||||
* @package PhpMyAdmin-DBI
|
||||
* @subpackage Dummy
|
||||
*/
|
||||
namespace PhpMyAdmin\Dbi;
|
||||
|
||||
require_once 'libraries/dbi/dbi_dummy.inc.php';
|
||||
|
||||
/**
|
||||
* Fake database driver for testing purposes
|
||||
*
|
||||
* It has hardcoded results for given queries what makes easy to use it
|
||||
* in testsuite. Feel free to include other queries which your test will
|
||||
* need.
|
||||
*
|
||||
* @package PhpMyAdmin-DBI
|
||||
* @subpackage Dummy
|
||||
*/
|
||||
class DbiDummy implements DbiExtension
|
||||
{
|
||||
private $_queries = array();
|
||||
const OFFSET_GLOBAL = 1000;
|
||||
|
||||
/**
|
||||
* connects to the database server
|
||||
*
|
||||
* @param string $user mysql user name
|
||||
* @param string $password mysql user password
|
||||
* @param array $server host/port/socket/persistent
|
||||
*
|
||||
* @return mixed false on error or a mysqli object on success
|
||||
*/
|
||||
public function connect(
|
||||
$user,
|
||||
$password,
|
||||
array $server = []
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* selects given database
|
||||
*
|
||||
* @param string $dbname name of db to select
|
||||
* @param resource $link mysql link resource
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function selectDb($dbname, $link)
|
||||
{
|
||||
$GLOBALS['dummy_db'] = $dbname;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* runs a query and returns the result
|
||||
*
|
||||
* @param string $query query to run
|
||||
* @param resource $link mysql link resource
|
||||
* @param int $options query options
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function realQuery($query, $link = null, $options = 0)
|
||||
{
|
||||
$query = trim(preg_replace('/ */', ' ', str_replace("\n", ' ', $query)));
|
||||
for ($i = 0, $nb = count($this->_queries); $i < $nb; $i++) {
|
||||
if ($this->_queries[$i]['query'] != $query) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->_queries[$i]['pos'] = 0;
|
||||
if (!is_array($this->_queries[$i]['result'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $i;
|
||||
}
|
||||
for ($i = 0, $nb = count($GLOBALS['dummy_queries']); $i < $nb; $i++) {
|
||||
if ($GLOBALS['dummy_queries'][$i]['query'] != $query) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$GLOBALS['dummy_queries'][$i]['pos'] = 0;
|
||||
if (!is_array($GLOBALS['dummy_queries'][$i]['result'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $i + self::OFFSET_GLOBAL;
|
||||
}
|
||||
echo "Not supported query: $query\n";
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the multi query and output the results
|
||||
*
|
||||
* @param resource $link connection object
|
||||
* @param string $query multi query statement to execute
|
||||
*
|
||||
* @return array|bool
|
||||
*/
|
||||
public function realMultiQuery($link, $query)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns result data from $result
|
||||
*
|
||||
* @param object $result MySQL result
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function fetchAny($result)
|
||||
{
|
||||
$query_data = &$this->getQueryData($result);
|
||||
if ($query_data['pos'] >= count($query_data['result'])) {
|
||||
return false;
|
||||
}
|
||||
$ret = $query_data['result'][$query_data['pos']];
|
||||
$query_data['pos'] += 1;
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns array of rows with associative and numeric keys from $result
|
||||
*
|
||||
* @param object $result result MySQL result
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function fetchArray($result)
|
||||
{
|
||||
$query_data = &$this->getQueryData($result);
|
||||
$data = $this->fetchAny($result);
|
||||
if (!is_array($data)
|
||||
|| !isset($query_data['columns'])
|
||||
) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
foreach ($data as $key => $val) {
|
||||
$data[$query_data['columns'][$key]] = $val;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns array of rows with associative keys from $result
|
||||
*
|
||||
* @param object $result MySQL result
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function fetchAssoc($result)
|
||||
{
|
||||
$data = $this->fetchAny($result);
|
||||
$query_data = &$this->getQueryData($result);
|
||||
if (!is_array($data) || !isset($query_data['columns'])) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
$ret = array();
|
||||
foreach ($data as $key => $val) {
|
||||
$ret[$query_data['columns'][$key]] = $val;
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns array of rows with numeric keys from $result
|
||||
*
|
||||
* @param object $result MySQL result
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function fetchRow($result)
|
||||
{
|
||||
$data = $this->fetchAny($result);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjusts the result pointer to an arbitrary row in the result
|
||||
*
|
||||
* @param object $result database result
|
||||
* @param integer $offset offset to seek
|
||||
*
|
||||
* @return bool true on success, false on failure
|
||||
*/
|
||||
public function dataSeek($result, $offset)
|
||||
{
|
||||
$query_data = &$this->getQueryData($result);
|
||||
if ($offset > count($query_data['result'])) {
|
||||
return false;
|
||||
}
|
||||
$query_data['pos'] = $offset;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Frees memory associated with the result
|
||||
*
|
||||
* @param object $result database result
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function freeResult($result)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if there are any more query results from a multi query
|
||||
*
|
||||
* @param resource $link the connection object
|
||||
*
|
||||
* @return bool false
|
||||
*/
|
||||
public function moreResults($link)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare next result from multi_query
|
||||
*
|
||||
* @param resource $link the connection object
|
||||
*
|
||||
* @return boolean false
|
||||
*/
|
||||
public function nextResult($link)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the result returned from multi query
|
||||
*
|
||||
* @param resource $link the connection object
|
||||
*
|
||||
* @return mixed false when empty results / result set when not empty
|
||||
*/
|
||||
public function storeResult($link)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representing the type of connection used
|
||||
*
|
||||
* @param resource $link mysql link
|
||||
*
|
||||
* @return string type of connection used
|
||||
*/
|
||||
public function getHostInfo($link)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the version of the MySQL protocol used
|
||||
*
|
||||
* @param resource $link mysql link
|
||||
*
|
||||
* @return integer version of the MySQL protocol used
|
||||
*/
|
||||
public function getProtoInfo($link)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a string that represents the client library version
|
||||
*
|
||||
* @return string MySQL client library version
|
||||
*/
|
||||
public function getClientInfo()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* returns last error message or false if no errors occurred
|
||||
*
|
||||
* @param resource $link connection link
|
||||
*
|
||||
* @return string|bool $error or false
|
||||
*/
|
||||
public function getError($link)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the number of rows returned by last query
|
||||
*
|
||||
* @param object $result MySQL result
|
||||
*
|
||||
* @return string|int
|
||||
*/
|
||||
public function numRows($result)
|
||||
{
|
||||
if (is_bool($result)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$query_data = &$this->getQueryData($result);
|
||||
|
||||
return count($query_data['result']);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the number of rows affected by last query
|
||||
*
|
||||
* @param resource $link the mysql object
|
||||
* @param bool $get_from_cache whether to retrieve from cache
|
||||
*
|
||||
* @return string|int
|
||||
*/
|
||||
public function affectedRows($link = null, $get_from_cache = true)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns metainfo for fields in $result
|
||||
*
|
||||
* @param object $result result set identifier
|
||||
*
|
||||
* @return array meta info for fields in $result
|
||||
*/
|
||||
public function getFieldsMeta($result)
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* return number of fields in given $result
|
||||
*
|
||||
* @param object $result MySQL result
|
||||
*
|
||||
* @return int field count
|
||||
*/
|
||||
public function numFields($result)
|
||||
{
|
||||
$query_data = &$this->getQueryData($result);
|
||||
if (!isset($query_data['columns'])) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return count($query_data['columns']);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the length of the given field $i in $result
|
||||
*
|
||||
* @param object $result result set identifier
|
||||
* @param int $i field
|
||||
*
|
||||
* @return int length of field
|
||||
*/
|
||||
public function fieldLen($result, $i)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns name of $i. field in $result
|
||||
*
|
||||
* @param object $result result set identifier
|
||||
* @param int $i field
|
||||
*
|
||||
* @return string name of $i. field in $result
|
||||
*/
|
||||
public function fieldName($result, $i)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* returns concatenated string of human readable field flags
|
||||
*
|
||||
* @param object $result result set identifier
|
||||
* @param int $i field
|
||||
*
|
||||
* @return string field flags
|
||||
*/
|
||||
public function fieldFlags($result, $i)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* returns properly escaped string for use in MySQL queries
|
||||
*
|
||||
* @param mixed $link database link
|
||||
* @param string $str string to be escaped
|
||||
*
|
||||
* @return string a MySQL escaped string
|
||||
*/
|
||||
public function escapeString($link, $str)
|
||||
{
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds query result for testing
|
||||
*
|
||||
* @param string $query SQL
|
||||
* @param array $result Expected result
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setResult($query, $result)
|
||||
{
|
||||
$this->_queries[] = array(
|
||||
'query' => $query,
|
||||
'result' => $result,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return query data for ID
|
||||
*
|
||||
* @param object $result result set identifier
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function &getQueryData($result)
|
||||
{
|
||||
if ($result >= self::OFFSET_GLOBAL) {
|
||||
return $GLOBALS['dummy_queries'][$result - self::OFFSET_GLOBAL];
|
||||
} else {
|
||||
return $this->_queries[$result];
|
||||
}
|
||||
}
|
||||
}
|
||||
242
phpMyAdmin/libraries/classes/Dbi/DbiExtension.php
Executable file
242
phpMyAdmin/libraries/classes/Dbi/DbiExtension.php
Executable file
@@ -0,0 +1,242 @@
|
||||
<?php
|
||||
/**
|
||||
* Contract for every database extension supported by phpMyAdmin
|
||||
*
|
||||
* @package PhpMyAdmin-DBI
|
||||
*/
|
||||
namespace PhpMyAdmin\Dbi;
|
||||
|
||||
/**
|
||||
* Contract for every database extension supported by phpMyAdmin
|
||||
*
|
||||
* @package PhpMyAdmin-DBI
|
||||
*/
|
||||
interface DbiExtension
|
||||
{
|
||||
/**
|
||||
* connects to the database server
|
||||
*
|
||||
* @param string $user user name
|
||||
* @param string $password user password
|
||||
* @param array $server host/port/socket/persistent
|
||||
*
|
||||
* @return mixed false on error or a connection object on success
|
||||
*/
|
||||
public function connect(
|
||||
$user, $password, array $server
|
||||
);
|
||||
|
||||
/**
|
||||
* selects given database
|
||||
*
|
||||
* @param string $dbname database name to select
|
||||
* @param resource $link connection object
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function selectDb($dbname, $link);
|
||||
|
||||
/**
|
||||
* runs a query and returns the result
|
||||
*
|
||||
* @param string $query query to execute
|
||||
* @param resource $link connection object
|
||||
* @param int $options query options
|
||||
*
|
||||
* @return mixed result
|
||||
*/
|
||||
public function realQuery($query, $link, $options);
|
||||
|
||||
/**
|
||||
* Run the multi query and output the results
|
||||
*
|
||||
* @param resource $link connection object
|
||||
* @param string $query multi query statement to execute
|
||||
*
|
||||
* @return array|bool
|
||||
*/
|
||||
public function realMultiQuery($link, $query);
|
||||
|
||||
/**
|
||||
* returns array of rows with associative and numeric keys from $result
|
||||
*
|
||||
* @param object $result result set identifier
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function fetchArray($result);
|
||||
|
||||
/**
|
||||
* returns array of rows with associative keys from $result
|
||||
*
|
||||
* @param object $result result set identifier
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function fetchAssoc($result);
|
||||
|
||||
/**
|
||||
* returns array of rows with numeric keys from $result
|
||||
*
|
||||
* @param object $result result set identifier
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function fetchRow($result);
|
||||
|
||||
/**
|
||||
* Adjusts the result pointer to an arbitrary row in the result
|
||||
*
|
||||
* @param object $result database result
|
||||
* @param integer $offset offset to seek
|
||||
*
|
||||
* @return bool true on success, false on failure
|
||||
*/
|
||||
public function dataSeek($result, $offset);
|
||||
|
||||
/**
|
||||
* Frees memory associated with the result
|
||||
*
|
||||
* @param object $result database result
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function freeResult($result);
|
||||
|
||||
/**
|
||||
* Check if there are any more query results from a multi query
|
||||
*
|
||||
* @param resource $link the connection object
|
||||
*
|
||||
* @return bool true or false
|
||||
*/
|
||||
public function moreResults($link);
|
||||
|
||||
/**
|
||||
* Prepare next result from multi_query
|
||||
*
|
||||
* @param resource $link the connection object
|
||||
*
|
||||
* @return bool true or false
|
||||
*/
|
||||
public function nextResult($link);
|
||||
|
||||
/**
|
||||
* Store the result returned from multi query
|
||||
*
|
||||
* @param resource $link mysql link
|
||||
*
|
||||
* @return mixed false when empty results / result set when not empty
|
||||
*/
|
||||
public function storeResult($link);
|
||||
|
||||
/**
|
||||
* Returns a string representing the type of connection used
|
||||
*
|
||||
* @param resource $link mysql link
|
||||
*
|
||||
* @return string type of connection used
|
||||
*/
|
||||
public function getHostInfo($link);
|
||||
|
||||
/**
|
||||
* Returns the version of the MySQL protocol used
|
||||
*
|
||||
* @param resource $link mysql link
|
||||
*
|
||||
* @return integer version of the MySQL protocol used
|
||||
*/
|
||||
public function getProtoInfo($link);
|
||||
|
||||
/**
|
||||
* returns a string that represents the client library version
|
||||
*
|
||||
* @return string MySQL client library version
|
||||
*/
|
||||
public function getClientInfo();
|
||||
|
||||
/**
|
||||
* returns last error message or false if no errors occurred
|
||||
*
|
||||
* @param resource $link connection link
|
||||
*
|
||||
* @return string|bool $error or false
|
||||
*/
|
||||
public function getError($link);
|
||||
|
||||
/**
|
||||
* returns the number of rows returned by last query
|
||||
*
|
||||
* @param object $result result set identifier
|
||||
*
|
||||
* @return string|int
|
||||
*/
|
||||
public function numRows($result);
|
||||
|
||||
/**
|
||||
* returns the number of rows affected by last query
|
||||
*
|
||||
* @param resource $link the connection object
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function affectedRows($link);
|
||||
|
||||
/**
|
||||
* returns metainfo for fields in $result
|
||||
*
|
||||
* @param object $result result set identifier
|
||||
*
|
||||
* @return array meta info for fields in $result
|
||||
*/
|
||||
public function getFieldsMeta($result);
|
||||
|
||||
/**
|
||||
* return number of fields in given $result
|
||||
*
|
||||
* @param object $result result set identifier
|
||||
*
|
||||
* @return int field count
|
||||
*/
|
||||
public function numFields($result);
|
||||
|
||||
/**
|
||||
* returns the length of the given field $i in $result
|
||||
*
|
||||
* @param object $result result set identifier
|
||||
* @param int $i field
|
||||
*
|
||||
* @return int length of field
|
||||
*/
|
||||
public function fieldLen($result, $i);
|
||||
|
||||
/**
|
||||
* returns name of $i. field in $result
|
||||
*
|
||||
* @param object $result result set identifier
|
||||
* @param int $i field
|
||||
*
|
||||
* @return string name of $i. field in $result
|
||||
*/
|
||||
public function fieldName($result, $i);
|
||||
|
||||
/**
|
||||
* returns concatenated string of human readable field flags
|
||||
*
|
||||
* @param object $result result set identifier
|
||||
* @param int $i field
|
||||
*
|
||||
* @return string field flags
|
||||
*/
|
||||
public function fieldFlags($result, $i);
|
||||
|
||||
/**
|
||||
* returns properly escaped string for use in MySQL queries
|
||||
*
|
||||
* @param mixed $link database link
|
||||
* @param string $str string to be escaped
|
||||
*
|
||||
* @return string a MySQL escaped string
|
||||
*/
|
||||
public function escapeString($link, $str);
|
||||
}
|
||||
461
phpMyAdmin/libraries/classes/Dbi/DbiMysql.php
Executable file
461
phpMyAdmin/libraries/classes/Dbi/DbiMysql.php
Executable file
@@ -0,0 +1,461 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Interface to the classic MySQL extension
|
||||
*
|
||||
* @package PhpMyAdmin-DBI
|
||||
* @subpackage MySQL
|
||||
*/
|
||||
namespace PhpMyAdmin\Dbi;
|
||||
|
||||
use PhpMyAdmin\Core;
|
||||
use PhpMyAdmin\DatabaseInterface;
|
||||
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
if (! extension_loaded('mysql')) {
|
||||
// The old MySQL extension is deprecated as of PHP 5.5.0, and will be
|
||||
// removed in the future. Instead, the `MySQLi` or `PDO_MySQL` extension
|
||||
// should be used.
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface to the classic MySQL extension
|
||||
*
|
||||
* @package PhpMyAdmin-DBI
|
||||
* @subpackage MySQL
|
||||
*/
|
||||
class DbiMysql implements DbiExtension
|
||||
{
|
||||
/**
|
||||
* Helper function for connecting to the database server
|
||||
*
|
||||
* @param string $server host/port/socket
|
||||
* @param string $user mysql user name
|
||||
* @param string $password mysql user password
|
||||
* @param int $client_flags client flags of connection
|
||||
* @param bool $persistent whether to use persistent connection
|
||||
*
|
||||
* @return mixed false on error or a mysql connection resource on success
|
||||
*/
|
||||
private function _realConnect($server, $user, $password, $client_flags,
|
||||
$persistent = false
|
||||
) {
|
||||
global $cfg;
|
||||
|
||||
if (ini_get('mysql.allow_local_infile')) {
|
||||
Core::fatalError(__('Please disable mysql.allow_local_infile in your PHP configuration or install the mysqli extension.'));
|
||||
}
|
||||
|
||||
if (empty($client_flags)) {
|
||||
if ($cfg['PersistentConnections'] || $persistent) {
|
||||
$link = @mysql_pconnect($server, $user, $password);
|
||||
} else {
|
||||
$link = @mysql_connect($server, $user, $password);
|
||||
}
|
||||
} else {
|
||||
if ($cfg['PersistentConnections'] || $persistent) {
|
||||
$link = @mysql_pconnect($server, $user, $password, $client_flags);
|
||||
} else {
|
||||
$link = @mysql_connect(
|
||||
$server, $user, $password, false, $client_flags
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $link;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the multi query and output the results
|
||||
*
|
||||
* @param mysqli $link mysqli object
|
||||
* @param string $query multi query statement to execute
|
||||
*
|
||||
* @return boolean false always false since mysql extension not support
|
||||
* for multi query executions
|
||||
*/
|
||||
public function realMultiQuery($link, $query)
|
||||
{
|
||||
// N.B.: PHP's 'mysql' extension does not support
|
||||
// multi_queries so this function will always
|
||||
// return false. Use the 'mysqli' extension, if
|
||||
// you need support for multi_queries.
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* connects to the database server
|
||||
*
|
||||
* @param string $user mysql user name
|
||||
* @param string $password mysql user password
|
||||
* @param array $server host/port/socket/persistent
|
||||
*
|
||||
* @return mixed false on error or a mysqli object on success
|
||||
*/
|
||||
public function connect(
|
||||
$user, $password, array $server
|
||||
) {
|
||||
if ($server['port'] === 0) {
|
||||
$server_port = '';
|
||||
} else {
|
||||
$server_port = ':' . $server['port'];
|
||||
}
|
||||
|
||||
if (is_null($server['socket'])) {
|
||||
$server_socket = '';
|
||||
} else {
|
||||
$server_socket = ':' . $server['socket'];
|
||||
}
|
||||
|
||||
$client_flags = 0;
|
||||
|
||||
if (defined('PMA_ENABLE_LDI')) {
|
||||
// use CLIENT_LOCAL_FILES as defined in mysql_com.h
|
||||
// for the case where the client library was not compiled
|
||||
// with --enable-local-infile
|
||||
$client_flags |= 128;
|
||||
}
|
||||
|
||||
/* Optionally compress connection */
|
||||
if (defined('MYSQL_CLIENT_COMPRESS') && $server['compress']) {
|
||||
$client_flags |= MYSQL_CLIENT_COMPRESS;
|
||||
}
|
||||
|
||||
/* Optionally enable SSL */
|
||||
if (defined('MYSQL_CLIENT_SSL') && $server['ssl']) {
|
||||
$client_flags |= MYSQL_CLIENT_SSL;
|
||||
}
|
||||
|
||||
if (!isset($server['host'])) {
|
||||
$link = $this->_realConnect($server_socket, $user, $password, null);
|
||||
} else {
|
||||
$link = $this->_realConnect(
|
||||
$server['host'] . $server_port . $server_socket,
|
||||
$user, $password, null
|
||||
);
|
||||
}
|
||||
return $link;
|
||||
}
|
||||
|
||||
/**
|
||||
* selects given database
|
||||
*
|
||||
* @param string $dbname name of db to select
|
||||
* @param resource|null $link mysql link resource
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function selectDb($dbname, $link)
|
||||
{
|
||||
return mysql_select_db($dbname, $link);
|
||||
}
|
||||
|
||||
/**
|
||||
* runs a query and returns the result
|
||||
*
|
||||
* @param string $query query to run
|
||||
* @param resource|null $link mysql link resource
|
||||
* @param int $options query options
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function realQuery($query, $link, $options)
|
||||
{
|
||||
if ($options == ($options | DatabaseInterface::QUERY_STORE)) {
|
||||
return mysql_query($query, $link);
|
||||
} elseif ($options == ($options | DatabaseInterface::QUERY_UNBUFFERED)) {
|
||||
return mysql_unbuffered_query($query, $link);
|
||||
}
|
||||
|
||||
return mysql_query($query, $link);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns array of rows with associative and numeric keys from $result
|
||||
*
|
||||
* @param resource $result result MySQL result
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function fetchArray($result)
|
||||
{
|
||||
return mysql_fetch_array($result, MYSQL_BOTH);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns array of rows with associative keys from $result
|
||||
*
|
||||
* @param resource $result MySQL result
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function fetchAssoc($result)
|
||||
{
|
||||
return mysql_fetch_array($result, MYSQL_ASSOC);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns array of rows with numeric keys from $result
|
||||
*
|
||||
* @param resource $result MySQL result
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function fetchRow($result)
|
||||
{
|
||||
return mysql_fetch_array($result, MYSQL_NUM);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjusts the result pointer to an arbitrary row in the result
|
||||
*
|
||||
* @param resource $result database result
|
||||
* @param integer $offset offset to seek
|
||||
*
|
||||
* @return bool true on success, false on failure
|
||||
*/
|
||||
public function dataSeek($result, $offset)
|
||||
{
|
||||
return mysql_data_seek($result, $offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Frees memory associated with the result
|
||||
*
|
||||
* @param resource $result database result
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function freeResult($result)
|
||||
{
|
||||
if (is_resource($result) && get_resource_type($result) === 'mysql result') {
|
||||
mysql_free_result($result);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if there are any more query results from a multi query
|
||||
*
|
||||
* @param resource $link the connection object
|
||||
*
|
||||
* @return bool false
|
||||
*/
|
||||
public function moreResults($link)
|
||||
{
|
||||
// N.B.: PHP's 'mysql' extension does not support
|
||||
// multi_queries so this function will always
|
||||
// return false. Use the 'mysqli' extension, if
|
||||
// you need support for multi_queries.
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare next result from multi_query
|
||||
*
|
||||
* @param resource $link the connection object
|
||||
*
|
||||
* @return boolean false
|
||||
*/
|
||||
public function nextResult($link)
|
||||
{
|
||||
// N.B.: PHP's 'mysql' extension does not support
|
||||
// multi_queries so this function will always
|
||||
// return false. Use the 'mysqli' extension, if
|
||||
// you need support for multi_queries.
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representing the type of connection used
|
||||
*
|
||||
* @param resource|null $link mysql link
|
||||
*
|
||||
* @return string type of connection used
|
||||
*/
|
||||
public function getHostInfo($link)
|
||||
{
|
||||
return mysql_get_host_info($link);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the version of the MySQL protocol used
|
||||
*
|
||||
* @param resource|null $link mysql link
|
||||
*
|
||||
* @return int version of the MySQL protocol used
|
||||
*/
|
||||
public function getProtoInfo($link)
|
||||
{
|
||||
return mysql_get_proto_info($link);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a string that represents the client library version
|
||||
*
|
||||
* @return string MySQL client library version
|
||||
*/
|
||||
public function getClientInfo()
|
||||
{
|
||||
return mysql_get_client_info();
|
||||
}
|
||||
|
||||
/**
|
||||
* returns last error message or false if no errors occurred
|
||||
*
|
||||
* @param resource|null $link mysql link
|
||||
*
|
||||
* @return string|bool $error or false
|
||||
*/
|
||||
public function getError($link)
|
||||
{
|
||||
$GLOBALS['errno'] = 0;
|
||||
|
||||
if (null !== $link && false !== $link) {
|
||||
$error_number = mysql_errno($link);
|
||||
$error_message = mysql_error($link);
|
||||
} else {
|
||||
$error_number = mysql_errno();
|
||||
$error_message = mysql_error();
|
||||
}
|
||||
if (0 == $error_number) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// keep the error number for further check after
|
||||
// the call to getError()
|
||||
$GLOBALS['errno'] = $error_number;
|
||||
|
||||
return $GLOBALS['dbi']->formatError($error_number, $error_message);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the number of rows returned by last query
|
||||
*
|
||||
* @param resource $result MySQL result
|
||||
*
|
||||
* @return string|int
|
||||
*/
|
||||
public function numRows($result)
|
||||
{
|
||||
if (is_bool($result)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return mysql_num_rows($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the number of rows affected by last query
|
||||
*
|
||||
* @param resource|null $link the mysql object
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function affectedRows($link)
|
||||
{
|
||||
return mysql_affected_rows($link);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns metainfo for fields in $result
|
||||
*
|
||||
* @param resource $result MySQL result
|
||||
*
|
||||
* @return array meta info for fields in $result
|
||||
*
|
||||
* @todo add missing keys like in mysqli_query (decimals)
|
||||
*/
|
||||
public function getFieldsMeta($result)
|
||||
{
|
||||
$fields = array();
|
||||
$num_fields = mysql_num_fields($result);
|
||||
for ($i = 0; $i < $num_fields; $i++) {
|
||||
$field = mysql_fetch_field($result, $i);
|
||||
$field->flags = mysql_field_flags($result, $i);
|
||||
$field->orgtable = mysql_field_table($result, $i);
|
||||
$field->orgname = mysql_field_name($result, $i);
|
||||
$fields[] = $field;
|
||||
}
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* return number of fields in given $result
|
||||
*
|
||||
* @param resource $result MySQL result
|
||||
*
|
||||
* @return int field count
|
||||
*/
|
||||
public function numFields($result)
|
||||
{
|
||||
return mysql_num_fields($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the length of the given field $i in $result
|
||||
*
|
||||
* @param resource $result MySQL result
|
||||
* @param int $i field
|
||||
*
|
||||
* @return int length of field
|
||||
*/
|
||||
public function fieldLen($result, $i)
|
||||
{
|
||||
return mysql_field_len($result, $i);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns name of $i. field in $result
|
||||
*
|
||||
* @param resource $result MySQL result
|
||||
* @param int $i field
|
||||
*
|
||||
* @return string name of $i. field in $result
|
||||
*/
|
||||
public function fieldName($result, $i)
|
||||
{
|
||||
return mysql_field_name($result, $i);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns concatenated string of human readable field flags
|
||||
*
|
||||
* @param resource $result MySQL result
|
||||
* @param int $i field
|
||||
*
|
||||
* @return string field flags
|
||||
*/
|
||||
public function fieldFlags($result, $i)
|
||||
{
|
||||
return mysql_field_flags($result, $i);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the result returned from multi query
|
||||
*
|
||||
* @param resource $result MySQL result
|
||||
*
|
||||
* @return false
|
||||
*/
|
||||
public function storeResult($result)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns properly escaped string for use in MySQL queries
|
||||
*
|
||||
* @param mixed $link database link
|
||||
* @param string $str string to be escaped
|
||||
*
|
||||
* @return string a MySQL escaped string
|
||||
*/
|
||||
public function escapeString($link, $str)
|
||||
{
|
||||
return mysql_real_escape_string($str, $link);
|
||||
}
|
||||
}
|
||||
637
phpMyAdmin/libraries/classes/Dbi/DbiMysqli.php
Executable file
637
phpMyAdmin/libraries/classes/Dbi/DbiMysqli.php
Executable file
@@ -0,0 +1,637 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Interface to the improved MySQL extension (MySQLi)
|
||||
*
|
||||
* @package PhpMyAdmin-DBI
|
||||
* @subpackage MySQLi
|
||||
*/
|
||||
namespace PhpMyAdmin\Dbi;
|
||||
|
||||
use PhpMyAdmin\DatabaseInterface;
|
||||
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* some PHP versions are reporting extra messages like "No index used in query"
|
||||
*/
|
||||
|
||||
mysqli_report(MYSQLI_REPORT_OFF);
|
||||
|
||||
/**
|
||||
* some older mysql client libs are missing these constants ...
|
||||
*/
|
||||
if (! defined('MYSQLI_BINARY_FLAG')) {
|
||||
define('MYSQLI_BINARY_FLAG', 128);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see https://bugs.php.net/36007
|
||||
*/
|
||||
if (! defined('MYSQLI_TYPE_NEWDECIMAL')) {
|
||||
define('MYSQLI_TYPE_NEWDECIMAL', 246);
|
||||
}
|
||||
if (! defined('MYSQLI_TYPE_BIT')) {
|
||||
define('MYSQLI_TYPE_BIT', 16);
|
||||
}
|
||||
if (! defined('MYSQLI_TYPE_JSON')) {
|
||||
define('MYSQLI_TYPE_JSON', 245);
|
||||
}
|
||||
|
||||
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Interface to the improved MySQL extension (MySQLi)
|
||||
*
|
||||
* @package PhpMyAdmin-DBI
|
||||
* @subpackage MySQLi
|
||||
*/
|
||||
class DbiMysqli implements DbiExtension
|
||||
{
|
||||
static private $pma_mysqli_flag_names = array(
|
||||
MYSQLI_NUM_FLAG => 'num',
|
||||
MYSQLI_PART_KEY_FLAG => 'part_key',
|
||||
MYSQLI_SET_FLAG => 'set',
|
||||
MYSQLI_TIMESTAMP_FLAG => 'timestamp',
|
||||
MYSQLI_AUTO_INCREMENT_FLAG => 'auto_increment',
|
||||
MYSQLI_ENUM_FLAG => 'enum',
|
||||
MYSQLI_ZEROFILL_FLAG => 'zerofill',
|
||||
MYSQLI_UNSIGNED_FLAG => 'unsigned',
|
||||
MYSQLI_BLOB_FLAG => 'blob',
|
||||
MYSQLI_MULTIPLE_KEY_FLAG => 'multiple_key',
|
||||
MYSQLI_UNIQUE_KEY_FLAG => 'unique_key',
|
||||
MYSQLI_PRI_KEY_FLAG => 'primary_key',
|
||||
MYSQLI_NOT_NULL_FLAG => 'not_null',
|
||||
);
|
||||
|
||||
/**
|
||||
* connects to the database server
|
||||
*
|
||||
* @param string $user mysql user name
|
||||
* @param string $password mysql user password
|
||||
* @param array $server host/port/socket/persistent
|
||||
*
|
||||
* @return mixed false on error or a mysqli object on success
|
||||
*/
|
||||
public function connect(
|
||||
$user, $password, array $server
|
||||
) {
|
||||
if ($server) {
|
||||
$server['host'] = (empty($server['host']))
|
||||
? 'localhost'
|
||||
: $server['host'];
|
||||
}
|
||||
|
||||
// NULL enables connection to the default socket
|
||||
|
||||
$link = mysqli_init();
|
||||
|
||||
$client_flags = 0;
|
||||
|
||||
/* Optionally compress connection */
|
||||
if ($server['compress'] && defined('MYSQLI_CLIENT_COMPRESS')) {
|
||||
$client_flags |= MYSQLI_CLIENT_COMPRESS;
|
||||
}
|
||||
|
||||
/* Optionally enable SSL */
|
||||
if ($server['ssl']) {
|
||||
$client_flags |= MYSQLI_CLIENT_SSL;
|
||||
if (! empty($server['ssl_key']) ||
|
||||
! empty($server['ssl_cert']) ||
|
||||
! empty($server['ssl_ca']) ||
|
||||
! empty($server['ssl_ca_path']) ||
|
||||
! empty($server['ssl_ciphers'])
|
||||
) {
|
||||
if (! isset($server['ssl_key']) || is_null($server['ssl_key'])) {
|
||||
$server['ssl_key'] = '';
|
||||
}
|
||||
if (! isset($server['ssl_cert']) || is_null($server['ssl_cert'])) {
|
||||
$server['ssl_cert'] = '';
|
||||
}
|
||||
if (! isset($server['ssl_ca']) || is_null($server['ssl_ca'])) {
|
||||
$server['ssl_ca'] = '';
|
||||
}
|
||||
if (! isset($server['ssl_ca_path']) || is_null($server['ssl_ca_path'])) {
|
||||
$server['ssl_ca_path'] = '';
|
||||
}
|
||||
if (! isset($server['ssl_ciphers']) || is_null($server['ssl_ciphers'])) {
|
||||
$server['ssl_ciphers'] = '';
|
||||
}
|
||||
mysqli_ssl_set(
|
||||
$link,
|
||||
$server['ssl_key'],
|
||||
$server['ssl_cert'],
|
||||
$server['ssl_ca'],
|
||||
$server['ssl_ca_path'],
|
||||
$server['ssl_ciphers']
|
||||
);
|
||||
}
|
||||
/*
|
||||
* disables SSL certificate validation on mysqlnd for MySQL 5.6 or later
|
||||
* @link https://bugs.php.net/bug.php?id=68344
|
||||
* @link https://github.com/phpmyadmin/phpmyadmin/pull/11838
|
||||
*/
|
||||
if (! $server['ssl_verify']) {
|
||||
mysqli_options(
|
||||
$link,
|
||||
MYSQLI_OPT_SSL_VERIFY_SERVER_CERT,
|
||||
$server['ssl_verify']
|
||||
);
|
||||
$client_flags |= MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT;
|
||||
}
|
||||
}
|
||||
|
||||
if ($GLOBALS['cfg']['PersistentConnections']) {
|
||||
$host = 'p:' . $server['host'];
|
||||
} else {
|
||||
$host = $server['host'];
|
||||
}
|
||||
|
||||
if ($server['hide_connection_errors']) {
|
||||
$return_value = @mysqli_real_connect(
|
||||
$link,
|
||||
$host,
|
||||
$user,
|
||||
$password,
|
||||
'',
|
||||
$server['port'],
|
||||
$server['socket'],
|
||||
$client_flags
|
||||
);
|
||||
} else {
|
||||
$return_value = mysqli_real_connect(
|
||||
$link,
|
||||
$host,
|
||||
$user,
|
||||
$password,
|
||||
'',
|
||||
$server['port'],
|
||||
$server['socket'],
|
||||
$client_flags
|
||||
);
|
||||
}
|
||||
|
||||
if ($return_value === false || is_null($return_value)) {
|
||||
/*
|
||||
* Switch to SSL if server asked us to do so, unfortunately
|
||||
* there are more ways MySQL server can tell this:
|
||||
*
|
||||
* - MySQL 8.0 and newer should return error 3159
|
||||
* - #2001 - SSL Connection is required. Please specify SSL options and retry.
|
||||
* - #9002 - SSL connection is required. Please specify SSL options and retry.
|
||||
*/
|
||||
$error_number = mysqli_connect_errno();
|
||||
$error_message = mysqli_connect_error();
|
||||
if (! $server['ssl'] && ($error_number == 3159 ||
|
||||
(($error_number == 2001 || $error_number == 9002) && stripos($error_message, 'SSL Connection is required') !== false))
|
||||
) {
|
||||
trigger_error(
|
||||
__('SSL connection enforced by server, automatically enabling it.'),
|
||||
E_USER_WARNING
|
||||
);
|
||||
$server['ssl'] = true;
|
||||
return self::connect($user, $password, $server);
|
||||
} elseif ($error_number === 1045 && $server['hide_connection_errors']) {
|
||||
trigger_error(
|
||||
sprintf(
|
||||
__(
|
||||
'Error 1045: Access denied for user. Additional error information'
|
||||
. ' may be available, but is being hidden by the %s configuration directive.'
|
||||
),
|
||||
'[code][doc@cfg_Servers_hide_connection_errors]'
|
||||
. '$cfg[\'Servers\'][$i][\'hide_connection_errors\'][/doc][/code]'
|
||||
),
|
||||
E_USER_ERROR
|
||||
);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (defined('PMA_ENABLE_LDI')) {
|
||||
mysqli_options($link, MYSQLI_OPT_LOCAL_INFILE, true);
|
||||
} else {
|
||||
mysqli_options($link, MYSQLI_OPT_LOCAL_INFILE, false);
|
||||
}
|
||||
|
||||
return $link;
|
||||
}
|
||||
|
||||
/**
|
||||
* selects given database
|
||||
*
|
||||
* @param string $dbname database name to select
|
||||
* @param mysqli $link the mysqli object
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function selectDb($dbname, $link)
|
||||
{
|
||||
return mysqli_select_db($link, $dbname);
|
||||
}
|
||||
|
||||
/**
|
||||
* runs a query and returns the result
|
||||
*
|
||||
* @param string $query query to execute
|
||||
* @param mysqli $link mysqli object
|
||||
* @param int $options query options
|
||||
*
|
||||
* @return mysqli_result|bool
|
||||
*/
|
||||
public function realQuery($query, $link, $options)
|
||||
{
|
||||
if ($options == ($options | DatabaseInterface::QUERY_STORE)) {
|
||||
$method = MYSQLI_STORE_RESULT;
|
||||
} elseif ($options == ($options | DatabaseInterface::QUERY_UNBUFFERED)) {
|
||||
$method = MYSQLI_USE_RESULT;
|
||||
} else {
|
||||
$method = 0;
|
||||
}
|
||||
|
||||
return mysqli_query($link, $query, $method);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the multi query and output the results
|
||||
*
|
||||
* @param mysqli $link mysqli object
|
||||
* @param string $query multi query statement to execute
|
||||
*
|
||||
* @return mysqli_result collection | boolean(false)
|
||||
*/
|
||||
public function realMultiQuery($link, $query)
|
||||
{
|
||||
return mysqli_multi_query($link, $query);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns array of rows with associative and numeric keys from $result
|
||||
*
|
||||
* @param mysqli_result $result result set identifier
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function fetchArray($result)
|
||||
{
|
||||
return mysqli_fetch_array($result, MYSQLI_BOTH);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns array of rows with associative keys from $result
|
||||
*
|
||||
* @param mysqli_result $result result set identifier
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function fetchAssoc($result)
|
||||
{
|
||||
return mysqli_fetch_array($result, MYSQLI_ASSOC);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns array of rows with numeric keys from $result
|
||||
*
|
||||
* @param mysqli_result $result result set identifier
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function fetchRow($result)
|
||||
{
|
||||
return mysqli_fetch_array($result, MYSQLI_NUM);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjusts the result pointer to an arbitrary row in the result
|
||||
*
|
||||
* @param mysqli_result $result database result
|
||||
* @param integer $offset offset to seek
|
||||
*
|
||||
* @return bool true on success, false on failure
|
||||
*/
|
||||
public function dataSeek($result, $offset)
|
||||
{
|
||||
return mysqli_data_seek($result, $offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Frees memory associated with the result
|
||||
*
|
||||
* @param mysqli_result $result database result
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function freeResult($result)
|
||||
{
|
||||
if ($result instanceof mysqli_result) {
|
||||
mysqli_free_result($result);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if there are any more query results from a multi query
|
||||
*
|
||||
* @param mysqli $link the mysqli object
|
||||
*
|
||||
* @return bool true or false
|
||||
*/
|
||||
public function moreResults($link)
|
||||
{
|
||||
return mysqli_more_results($link);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare next result from multi_query
|
||||
*
|
||||
* @param mysqli $link the mysqli object
|
||||
*
|
||||
* @return bool true or false
|
||||
*/
|
||||
public function nextResult($link)
|
||||
{
|
||||
return mysqli_next_result($link);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the result returned from multi query
|
||||
*
|
||||
* @param mysqli $link the mysqli object
|
||||
*
|
||||
* @return mixed false when empty results / result set when not empty
|
||||
*/
|
||||
public function storeResult($link)
|
||||
{
|
||||
return mysqli_store_result($link);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representing the type of connection used
|
||||
*
|
||||
* @param resource $link mysql link
|
||||
*
|
||||
* @return string type of connection used
|
||||
*/
|
||||
public function getHostInfo($link)
|
||||
{
|
||||
return mysqli_get_host_info($link);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the version of the MySQL protocol used
|
||||
*
|
||||
* @param resource $link mysql link
|
||||
*
|
||||
* @return integer version of the MySQL protocol used
|
||||
*/
|
||||
public function getProtoInfo($link)
|
||||
{
|
||||
return mysqli_get_proto_info($link);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a string that represents the client library version
|
||||
*
|
||||
* @return string MySQL client library version
|
||||
*/
|
||||
public function getClientInfo()
|
||||
{
|
||||
return mysqli_get_client_info();
|
||||
}
|
||||
|
||||
/**
|
||||
* returns last error message or false if no errors occurred
|
||||
*
|
||||
* @param resource $link mysql link
|
||||
*
|
||||
* @return string|bool $error or false
|
||||
*/
|
||||
public function getError($link)
|
||||
{
|
||||
$GLOBALS['errno'] = 0;
|
||||
|
||||
if (null !== $link && false !== $link) {
|
||||
$error_number = mysqli_errno($link);
|
||||
$error_message = mysqli_error($link);
|
||||
} else {
|
||||
$error_number = mysqli_connect_errno();
|
||||
$error_message = mysqli_connect_error();
|
||||
}
|
||||
if (0 == $error_number) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// keep the error number for further check after
|
||||
// the call to getError()
|
||||
$GLOBALS['errno'] = $error_number;
|
||||
|
||||
return $GLOBALS['dbi']->formatError($error_number, $error_message);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the number of rows returned by last query
|
||||
*
|
||||
* @param mysqli_result $result result set identifier
|
||||
*
|
||||
* @return string|int
|
||||
*/
|
||||
public function numRows($result)
|
||||
{
|
||||
// see the note for tryQuery();
|
||||
if (is_bool($result)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return @mysqli_num_rows($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the number of rows affected by last query
|
||||
*
|
||||
* @param mysqli $link the mysqli object
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function affectedRows($link)
|
||||
{
|
||||
return mysqli_affected_rows($link);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns metainfo for fields in $result
|
||||
*
|
||||
* @param mysqli_result $result result set identifier
|
||||
*
|
||||
* @return array meta info for fields in $result
|
||||
*/
|
||||
public function getFieldsMeta($result)
|
||||
{
|
||||
// Build an associative array for a type look up
|
||||
$typeAr = array();
|
||||
$typeAr[MYSQLI_TYPE_DECIMAL] = 'real';
|
||||
$typeAr[MYSQLI_TYPE_NEWDECIMAL] = 'real';
|
||||
$typeAr[MYSQLI_TYPE_BIT] = 'int';
|
||||
$typeAr[MYSQLI_TYPE_TINY] = 'int';
|
||||
$typeAr[MYSQLI_TYPE_SHORT] = 'int';
|
||||
$typeAr[MYSQLI_TYPE_LONG] = 'int';
|
||||
$typeAr[MYSQLI_TYPE_FLOAT] = 'real';
|
||||
$typeAr[MYSQLI_TYPE_DOUBLE] = 'real';
|
||||
$typeAr[MYSQLI_TYPE_NULL] = 'null';
|
||||
$typeAr[MYSQLI_TYPE_TIMESTAMP] = 'timestamp';
|
||||
$typeAr[MYSQLI_TYPE_LONGLONG] = 'int';
|
||||
$typeAr[MYSQLI_TYPE_INT24] = 'int';
|
||||
$typeAr[MYSQLI_TYPE_DATE] = 'date';
|
||||
$typeAr[MYSQLI_TYPE_TIME] = 'time';
|
||||
$typeAr[MYSQLI_TYPE_DATETIME] = 'datetime';
|
||||
$typeAr[MYSQLI_TYPE_YEAR] = 'year';
|
||||
$typeAr[MYSQLI_TYPE_NEWDATE] = 'date';
|
||||
$typeAr[MYSQLI_TYPE_ENUM] = 'unknown';
|
||||
$typeAr[MYSQLI_TYPE_SET] = 'unknown';
|
||||
$typeAr[MYSQLI_TYPE_TINY_BLOB] = 'blob';
|
||||
$typeAr[MYSQLI_TYPE_MEDIUM_BLOB] = 'blob';
|
||||
$typeAr[MYSQLI_TYPE_LONG_BLOB] = 'blob';
|
||||
$typeAr[MYSQLI_TYPE_BLOB] = 'blob';
|
||||
$typeAr[MYSQLI_TYPE_VAR_STRING] = 'string';
|
||||
$typeAr[MYSQLI_TYPE_STRING] = 'string';
|
||||
// MySQL returns MYSQLI_TYPE_STRING for CHAR
|
||||
// and MYSQLI_TYPE_CHAR === MYSQLI_TYPE_TINY
|
||||
// so this would override TINYINT and mark all TINYINT as string
|
||||
// see https://github.com/phpmyadmin/phpmyadmin/issues/8569
|
||||
//$typeAr[MYSQLI_TYPE_CHAR] = 'string';
|
||||
$typeAr[MYSQLI_TYPE_GEOMETRY] = 'geometry';
|
||||
$typeAr[MYSQLI_TYPE_BIT] = 'bit';
|
||||
$typeAr[MYSQLI_TYPE_JSON] = 'json';
|
||||
|
||||
$fields = mysqli_fetch_fields($result);
|
||||
|
||||
// this happens sometimes (seen under MySQL 4.0.25)
|
||||
if (!is_array($fields)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($fields as $k => $field) {
|
||||
$fields[$k]->_type = $field->type;
|
||||
$fields[$k]->type = $typeAr[$field->type];
|
||||
$fields[$k]->_flags = $field->flags;
|
||||
$fields[$k]->flags = $this->fieldFlags($result, $k);
|
||||
|
||||
// Enhance the field objects for mysql-extension compatibility
|
||||
//$flags = explode(' ', $fields[$k]->flags);
|
||||
//array_unshift($flags, 'dummy');
|
||||
$fields[$k]->multiple_key
|
||||
= (int) (bool) ($fields[$k]->_flags & MYSQLI_MULTIPLE_KEY_FLAG);
|
||||
$fields[$k]->primary_key
|
||||
= (int) (bool) ($fields[$k]->_flags & MYSQLI_PRI_KEY_FLAG);
|
||||
$fields[$k]->unique_key
|
||||
= (int) (bool) ($fields[$k]->_flags & MYSQLI_UNIQUE_KEY_FLAG);
|
||||
$fields[$k]->not_null
|
||||
= (int) (bool) ($fields[$k]->_flags & MYSQLI_NOT_NULL_FLAG);
|
||||
$fields[$k]->unsigned
|
||||
= (int) (bool) ($fields[$k]->_flags & MYSQLI_UNSIGNED_FLAG);
|
||||
$fields[$k]->zerofill
|
||||
= (int) (bool) ($fields[$k]->_flags & MYSQLI_ZEROFILL_FLAG);
|
||||
$fields[$k]->numeric
|
||||
= (int) (bool) ($fields[$k]->_flags & MYSQLI_NUM_FLAG);
|
||||
$fields[$k]->blob
|
||||
= (int) (bool) ($fields[$k]->_flags & MYSQLI_BLOB_FLAG);
|
||||
}
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* return number of fields in given $result
|
||||
*
|
||||
* @param mysqli_result $result result set identifier
|
||||
*
|
||||
* @return int field count
|
||||
*/
|
||||
public function numFields($result)
|
||||
{
|
||||
return mysqli_num_fields($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the length of the given field $i in $result
|
||||
*
|
||||
* @param mysqli_result $result result set identifier
|
||||
* @param int $i field
|
||||
*
|
||||
* @return int length of field
|
||||
*/
|
||||
public function fieldLen($result, $i)
|
||||
{
|
||||
if ($i >= $this->numFields($result)) {
|
||||
return false;
|
||||
}
|
||||
return mysqli_fetch_field_direct($result, $i)->length;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns name of $i. field in $result
|
||||
*
|
||||
* @param mysqli_result $result result set identifier
|
||||
* @param int $i field
|
||||
*
|
||||
* @return string name of $i. field in $result
|
||||
*/
|
||||
public function fieldName($result, $i)
|
||||
{
|
||||
if ($i >= $this->numFields($result)) {
|
||||
return false;
|
||||
}
|
||||
return mysqli_fetch_field_direct($result, $i)->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns concatenated string of human readable field flags
|
||||
*
|
||||
* @param mysqli_result $result result set identifier
|
||||
* @param int $i field
|
||||
*
|
||||
* @return string field flags
|
||||
*/
|
||||
public function fieldFlags($result, $i)
|
||||
{
|
||||
if ($i >= $this->numFields($result)) {
|
||||
return false;
|
||||
}
|
||||
$f = mysqli_fetch_field_direct($result, $i);
|
||||
$type = $f->type;
|
||||
$charsetnr = $f->charsetnr;
|
||||
$f = $f->flags;
|
||||
$flags = array();
|
||||
foreach (self::$pma_mysqli_flag_names as $flag => $name) {
|
||||
if ($f & $flag) {
|
||||
$flags[] = $name;
|
||||
}
|
||||
}
|
||||
// See https://dev.mysql.com/doc/refman/6.0/en/c-api-datatypes.html:
|
||||
// to determine if a string is binary, we should not use MYSQLI_BINARY_FLAG
|
||||
// but instead the charsetnr member of the MYSQL_FIELD
|
||||
// structure. Watch out: some types like DATE returns 63 in charsetnr
|
||||
// so we have to check also the type.
|
||||
// Unfortunately there is no equivalent in the mysql extension.
|
||||
if (($type == MYSQLI_TYPE_TINY_BLOB || $type == MYSQLI_TYPE_BLOB
|
||||
|| $type == MYSQLI_TYPE_MEDIUM_BLOB || $type == MYSQLI_TYPE_LONG_BLOB
|
||||
|| $type == MYSQLI_TYPE_VAR_STRING || $type == MYSQLI_TYPE_STRING)
|
||||
&& 63 == $charsetnr
|
||||
) {
|
||||
$flags[] = 'binary';
|
||||
}
|
||||
return implode(' ', $flags);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns properly escaped string for use in MySQL queries
|
||||
*
|
||||
* @param mixed $link database link
|
||||
* @param string $str string to be escaped
|
||||
*
|
||||
* @return string a MySQL escaped string
|
||||
*/
|
||||
public function escapeString($link, $str)
|
||||
{
|
||||
return mysqli_real_escape_string($link, $str);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user