The branch, master has been updated via e82682d0e4037d92305ad92cb5514e822e9a5abc (commit) via b9ff7b7ce279391e5a2538c182ee0419e3456fa3 (commit) via f43517efb525b8e4cfc387822308c206f32ba6ee (commit) via 46cd0f9a09e3a3fd0f2bb3b9b018282390c4e813 (commit) via b0ce7c20c4595a8a093177583cbdd5e15c6b6dca (commit) via 69ac50958439cc32f4fa313ebb096d90b3a10746 (commit) via 2141b5fe81d71d08524a11251a38fe5663b51ac7 (commit) from f89a16ed81e111abd7cf55d506ec944b4697ba4e (commit)
- Log ----------------------------------------------------------------- commit e82682d0e4037d92305ad92cb5514e822e9a5abc Author: Piotr Przybylski piotrprz@gmail.com Date: Wed Jul 27 19:54:22 2011 +0200
Simplify PMA_DBI_free_result It was never used with multiple arguments
commit b9ff7b7ce279391e5a2538c182ee0419e3456fa3 Author: Piotr Przybylski piotrprz@gmail.com Date: Wed Jul 27 19:51:09 2011 +0200
Support persistent connections with mysqli extension (only PHP 5.3.0 and newer)
commit f43517efb525b8e4cfc387822308c206f32ba6ee Author: Piotr Przybylski piotrprz@gmail.com Date: Wed Jul 27 19:37:51 2011 +0200
mysql extension - remove 'persistent' parameter Was named 'persistant' and never used/documented
commit 46cd0f9a09e3a3fd0f2bb3b9b018282390c4e813 Author: Piotr Przybylski piotrprz@gmail.com Date: Wed Jul 27 19:01:15 2011 +0200
Comments
commit b0ce7c20c4595a8a093177583cbdd5e15c6b6dca Author: Piotr Przybylski piotrprz@gmail.com Date: Wed Jul 27 17:31:23 2011 +0200
Improve readability
commit 69ac50958439cc32f4fa313ebb096d90b3a10746 Author: Piotr Przybylski piotrprz@gmail.com Date: Wed Jul 27 17:25:20 2011 +0200
This should be checked in common, not in dbi library
commit 2141b5fe81d71d08524a11251a38fe5663b51ac7 Author: Piotr Przybylski piotrprz@gmail.com Date: Wed Jul 27 17:20:14 2011 +0200
Fix incorrect variable name persistant > persistent
-----------------------------------------------------------------------
Summary of changes: Documentation.html | 8 ++- libraries/common.inc.php | 5 ++ libraries/dbi/mysql.dbi.lib.php | 97 ++++++++++++++++++-------- libraries/dbi/mysqli.dbi.lib.php | 139 ++++++++++++++++++++++---------------- 4 files changed, 160 insertions(+), 89 deletions(-)
diff --git a/Documentation.html b/Documentation.html index 33bfa85..26673cb 100644 --- a/Documentation.html +++ b/Documentation.html @@ -1391,8 +1391,12 @@ CREATE DATABASE,ALTER DATABASE,DROP DATABASE</pre> is known to cause data corruption when having enabled buffering.</dd>
<dt id="cfg_PersistentConnections">$cfg['PersistentConnections'] boolean</dt> - <dd>Whether persistent connections should be used or not (mysql_connect or - mysql_pconnect).</dd> + <dd>Whether <a href="http://php.net/manual/en/features.persistent-connections.php">persistent connections</a> + should be used or not. Works with following extensions: + <ul> + <li>mysql (<a href="http://php.net/manual/en/function.mysql-pconnect.php">mysql_pconnect</a>),</li> + <li>mysqli (requires PHP 5.3.0 or newer, <a href="http://php.net/manual/en/mysqli.persistconns.php">more information</a>).</li> + </ul></dd>
<dt id="cfg_ForceSSL">$cfg['ForceSSL'] boolean</dt> <dd>Whether to force using https while accessing phpMyAdmin.</dd> diff --git a/libraries/common.inc.php b/libraries/common.inc.php index 53cde17..2b2cf60 100644 --- a/libraries/common.inc.php +++ b/libraries/common.inc.php @@ -899,6 +899,11 @@ if (! defined('PMA_MINIMUM_COMMON')) { unset($login_without_password_is_forbidden); //Clean up after you! }
+ // if using TCP socket is not needed + if (strtolower($cfg['Server']['connect_type']) == 'tcp') { + $cfg['Server']['socket'] = ''; + } + // Try to connect MySQL with the control user profile (will be used to // get the privileges list for the current user but the true user link // must be open after this one so it would be default one for all the diff --git a/libraries/dbi/mysql.dbi.lib.php b/libraries/dbi/mysql.dbi.lib.php index aa099eb..ed8a93a 100644 --- a/libraries/dbi/mysql.dbi.lib.php +++ b/libraries/dbi/mysql.dbi.lib.php @@ -20,18 +20,28 @@ if (! defined('PMA_MYSQL_CLIENT_API')) { unset($client_api); }
-function PMA_DBI_real_connect($server, $user, $password, $client_flags, $persistant=false) +/** + * Helper function for connecting to the database server + * + * @param string $server + * @param string $user + * @param string $password + * @param int $client_flags + * @param boolean $persistent + * @return mixed false on error or a mysql connection resource on success + */ +function PMA_DBI_real_connect($server, $user, $password, $client_flags, $persistent = false) { global $cfg;
if (empty($client_flags)) { - if ($cfg['PersistentConnections'] || $persistant) { + if ($cfg['PersistentConnections'] || $persistent) { $link = @mysql_pconnect($server, $user, $password); } else { $link = @mysql_connect($server, $user, $password); } } else { - if ($cfg['PersistentConnections'] || $persistant) { + if ($cfg['PersistentConnections'] || $persistent) { $link = @mysql_pconnect($server, $user, $password, $client_flags); } else { $link = @mysql_connect($server, $user, $password, false, $client_flags); @@ -40,11 +50,14 @@ function PMA_DBI_real_connect($server, $user, $password, $client_flags, $persist
return $link; } + /** + * connects to the database server + * * @param string $user mysql user name * @param string $password mysql user password * @param boolean $is_controluser - * @param array $server host/port/socket/persistant + * @param array $server host/port/socket/persistent * @param boolean $auxiliary_connection (when true, don't go back to login if connection fails) * @return mixed false on error or a mysqli object on success */ @@ -59,9 +72,6 @@ function PMA_DBI_connect($user, $password, $is_controluser = false, $server = nu $server_socket = (empty($server['socket'])) ? '' : ':' . $server['socket']; - $server_persistant = (empty($server['persistant'])) - ? false - : true; } else { $server_port = (empty($cfg['Server']['port'])) ? '' @@ -71,10 +81,6 @@ function PMA_DBI_connect($user, $password, $is_controluser = false, $server = nu : ':' . $cfg['Server']['socket']; }
- if (strtolower($cfg['Server']['connect_type']) == 'tcp') { - $cfg['Server']['socket'] = ''; - } - $client_flags = 0;
// always use CLIENT_LOCAL_FILES as defined in mysql_com.h @@ -101,9 +107,9 @@ function PMA_DBI_connect($user, $password, $is_controluser = false, $server = nu } } else { if (!isset($server['host'])) { - $link = PMA_DBI_real_connect($server_socket, $user, $password, NULL, $server_persistant); + $link = PMA_DBI_real_connect($server_socket, $user, $password, NULL); } else { - $link = PMA_DBI_real_connect($server['host'] . $server_port . $server_socket, $user, $password, NULL, $server_persistant); + $link = PMA_DBI_real_connect($server['host'] . $server_port . $server_socket, $user, $password, NULL); } } if (empty($link)) { @@ -128,11 +134,11 @@ function PMA_DBI_connect($user, $password, $is_controluser = false, $server = nu }
/** - * select a db + * selects given database * - * @param string $dbname name of db to select - * @param resource $link mysql link resource - * @return boolean success + * @param string $dbname name of db to select + * @param resource $link mysql link resource + * @return boolean */ function PMA_DBI_select_db($dbname, $link = null) { @@ -149,9 +155,9 @@ function PMA_DBI_select_db($dbname, $link = null) /** * runs a query and returns the result * - * @param string $query query to run + * @param string $query query to run * @param resource $link mysql link resource - * @param integer $options + * @param integer $options * @return mixed */ function PMA_DBI_real_query($query, $link, $options) @@ -165,15 +171,33 @@ function PMA_DBI_real_query($query, $link, $options) } }
+/** + * returns array of rows with associative and numeric keys from $result + * + * @param resource $result + * @return array + */ function PMA_DBI_fetch_array($result) { return mysql_fetch_array($result, MYSQL_BOTH); }
+/** + * returns array of rows with associative keys from $result + * + * @param resource $result + * @return array + */ function PMA_DBI_fetch_assoc($result) { return mysql_fetch_array($result, MYSQL_ASSOC); }
+/** + * returns array of rows with numeric keys from $result + * + * @param resource $result + * @return array + */ function PMA_DBI_fetch_row($result) { return mysql_fetch_array($result, MYSQL_NUM); @@ -192,17 +216,14 @@ function PMA_DBI_data_seek($result, $offset) }
/** - * Frees the memory associated with the results + * Frees memory associated with the result * - * @param result $result,... one or more mysql result resources + * @param resource $result */ -function PMA_DBI_free_result() +function PMA_DBI_free_result($result) { - foreach (func_get_args() as $result) { - if (is_resource($result) - && get_resource_type($result) === 'mysql result') { - mysql_free_result($result); - } + if (is_resource($result) && get_resource_type($result) === 'mysql result') { + mysql_free_result($result); } }
@@ -337,6 +358,12 @@ function PMA_DBI_getError($link = null) return $error; }
+/** + * returns the number of rows returned by last query + * + * @param resource $result + * @return string|ineteger + */ function PMA_DBI_num_rows($result) { if (!is_bool($result)) { @@ -346,6 +373,12 @@ function PMA_DBI_num_rows($result) } }
+/** + * returns last inserted auto_increment id for given $link or $GLOBALS['userlink'] + * + * @param resource $link the mysql object + * @return string|ineteger + */ function PMA_DBI_insert_id($link = null) { if (empty($link)) { @@ -366,9 +399,9 @@ function PMA_DBI_insert_id($link = null) /** * returns the number of rows affected by last query * - * @param object mysql $link the mysql object - * @param boolean $get_from_cache - * @return string integer + * @param resource $link the mysql object + * @param boolean $get_from_cache + * @return string|integer */ function PMA_DBI_affected_rows($link = null, $get_from_cache = true) { @@ -388,7 +421,11 @@ function PMA_DBI_affected_rows($link = null, $get_from_cache = true) }
/** + * returns metainfo for fields in $result + * * @todo add missing keys like in from mysqli_query (orgname, orgtable, flags, decimals) + * @param resource $result + * @return array meta info for fields in $result */ function PMA_DBI_get_fields_meta($result) { diff --git a/libraries/dbi/mysqli.dbi.lib.php b/libraries/dbi/mysqli.dbi.lib.php index 0cd7c2f..535b825 100644 --- a/libraries/dbi/mysqli.dbi.lib.php +++ b/libraries/dbi/mysqli.dbi.lib.php @@ -44,6 +44,34 @@ if (! defined('MYSQLI_TYPE_BIT')) { }
/** + * Helper function for connecting to the database server + * + * @param mysqli $link + * @param string $host + * @param string $user + * @param string $password + * @param string $dbname + * @param int $server_port + * @param string $server_socket + * @param int $client_flags + * @param boolean $persistent + * @return boolean + */ +function PMA_DBI_real_connect($link, $host, $user, $password, $dbname, $server_port, $server_socket, $client_flags = null, $persistent = false) +{ + global $cfg; + + if ($cfg['PersistentConnections'] || $persistent) { + $host = 'p:' . $host; + } + if ($client_flags === null) { + return @mysqli_real_connect($link, $host, $user, $password, $dbname, $server_port, $server_socket); + } else { + return @mysqli_real_connect($link, $host, $user, $password, $dbname, $server_port, $server_socket, $client_flags); + } +} + +/** * connects to the database server * * @param string $user mysql user name @@ -55,6 +83,8 @@ if (! defined('MYSQLI_TYPE_BIT')) { */ function PMA_DBI_connect($user, $password, $is_controluser = false, $server = null, $auxiliary_connection = false) { + global $cfg; + if ($server) { $server_port = (empty($server['port'])) ? false @@ -66,17 +96,12 @@ function PMA_DBI_connect($user, $password, $is_controluser = false, $server = nu ? 'localhost' : $server['host']; } else { - $server_port = (empty($GLOBALS['cfg']['Server']['port'])) + $server_port = (empty($cfg['Server']['port'])) ? false - : (int) $GLOBALS['cfg']['Server']['port']; - $server_socket = (empty($GLOBALS['cfg']['Server']['socket'])) + : (int) $cfg['Server']['port']; + $server_socket = (empty($cfg['Server']['socket'])) ? null - : $GLOBALS['cfg']['Server']['socket']; - } - - - if (strtolower($GLOBALS['cfg']['Server']['connect_type']) == 'tcp') { - $GLOBALS['cfg']['Server']['socket'] = ''; + : $cfg['Server']['socket']; }
// NULL enables connection to the default socket @@ -88,23 +113,23 @@ function PMA_DBI_connect($user, $password, $is_controluser = false, $server = nu $client_flags = 0;
/* Optionally compress connection */ - if ($GLOBALS['cfg']['Server']['compress'] && defined('MYSQLI_CLIENT_COMPRESS')) { + if ($cfg['Server']['compress'] && defined('MYSQLI_CLIENT_COMPRESS')) { $client_flags |= MYSQLI_CLIENT_COMPRESS; }
/* Optionally enable SSL */ - if ($GLOBALS['cfg']['Server']['ssl'] && defined('MYSQLI_CLIENT_SSL')) { + if ($cfg['Server']['ssl'] && defined('MYSQLI_CLIENT_SSL')) { $client_flags |= MYSQLI_CLIENT_SSL; }
if (!$server) { - $return_value = @mysqli_real_connect($link, $GLOBALS['cfg']['Server']['host'], $user, $password, false, $server_port, $server_socket, $client_flags); + $return_value = @PMA_DBI_real_connect($link, $cfg['Server']['host'], $user, $password, false, $server_port, $server_socket, $client_flags); // Retry with empty password if we're allowed to - if ($return_value == false && isset($GLOBALS['cfg']['Server']['nopassword']) && $GLOBALS['cfg']['Server']['nopassword'] && !$is_controluser) { - $return_value = @mysqli_real_connect($link, $GLOBALS['cfg']['Server']['host'], $user, '', false, $server_port, $server_socket, $client_flags); + if ($return_value == false && isset($cfg['Server']['nopassword']) && $cfg['Server']['nopassword'] && !$is_controluser) { + $return_value = @PMA_DBI_real_connect($link, $cfg['Server']['host'], $user, '', false, $server_port, $server_socket, $client_flags); } } else { - $return_value = @mysqli_real_connect($link, $server['host'], $user, $password, false, $server_port, $server_socket); + $return_value = @PMA_DBI_real_connect($link, $server['host'], $user, $password, false, $server_port, $server_socket); }
if ($return_value == false) { @@ -131,9 +156,9 @@ function PMA_DBI_connect($user, $password, $is_controluser = false, $server = nu /** * selects given database * - * @param string $dbname database name to select - * @param object mysqli $link the mysqli object - * @return boolean true or false + * @param string $dbname database name to select + * @param mysqli $link the mysqli object + * @return boolean */ function PMA_DBI_select_db($dbname, $link = null) { @@ -150,10 +175,10 @@ function PMA_DBI_select_db($dbname, $link = null) /** * runs a query and returns the result * - * @param string $query query to execute - * @param object mysqli $link mysqli object - * @param integer $options - * @return mixed true, false or result object + * @param string $query query to execute + * @param mysqli $link mysqli object + * @param integer $options + * @return mysqli_result|boolean */ function PMA_DBI_real_query($query, $link, $options) { @@ -171,8 +196,8 @@ function PMA_DBI_real_query($query, $link, $options) /** * returns array of rows with associative and numeric keys from $result * - * @param object mysqli result $result - * @return array result rows + * @param mysqli_result $result + * @return array */ function PMA_DBI_fetch_array($result) { @@ -182,8 +207,8 @@ function PMA_DBI_fetch_array($result) /** * returns array of rows with associative keys from $result * - * @param object mysqli result $result - * @return array result rows + * @param mysqli_result $result + * @return array */ function PMA_DBI_fetch_assoc($result) { @@ -193,8 +218,8 @@ function PMA_DBI_fetch_assoc($result) /** * returns array of rows with numeric keys from $result * - * @param object mysqli result $result - * @return array result rows + * @param mysqli_result $result + * @return array */ function PMA_DBI_fetch_row($result) { @@ -214,23 +239,21 @@ function PMA_DBI_data_seek($result, $offset) }
/** - * Frees the memory associated with the results + * Frees memory associated with the result * - * @param result $result,... one or more mysql result resources + * @param mysqli_result $result */ -function PMA_DBI_free_result() +function PMA_DBI_free_result($result) { - foreach (func_get_args() as $result) { - if ($result instanceof mysqli_result) { - mysqli_free_result($result); - } + if ($result instanceof mysqli_result) { + mysqli_free_result($result); } }
/** * Check if there are any more query results from a multi query * - * @param object mysqli $link the mysqli object + * @param mysqli $link the mysqli object * @return boolean true or false */ function PMA_DBI_more_results($link = null) { @@ -247,7 +270,7 @@ function PMA_DBI_more_results($link = null) { /** * Prepare next result from multi_query * - * @param object mysqli $link the mysqli object + * @param mysqli $link the mysqli object * @return boolean true or false */ function PMA_DBI_next_result($link = null) { @@ -356,8 +379,10 @@ function PMA_DBI_getError($link = null) }
/** + * returns the number of rows returned by last query * - * @param object mysqli result $result + * @param mysqli_result $result + * @return string|ineteger */ function PMA_DBI_num_rows($result) { @@ -372,10 +397,10 @@ function PMA_DBI_num_rows($result) /** * returns last inserted auto_increment id for given $link or $GLOBALS['userlink'] * - * @param object mysqli $link the mysqli object - * @return string ineteger + * @param mysqli $link the mysqli object + * @return string|ineteger */ -function PMA_DBI_insert_id($link = '') +function PMA_DBI_insert_id($link = null) { if (empty($link)) { if (isset($GLOBALS['userlink'])) { @@ -396,9 +421,9 @@ function PMA_DBI_insert_id($link = '') /** * returns the number of rows affected by last query * - * @param object mysqli $link the mysqli object - * @param boolean $get_from_cache - * @return string integer + * @param mysqli $link the mysqli object + * @param boolean $get_from_cache + * @return string|integer */ function PMA_DBI_affected_rows($link = null, $get_from_cache = true) { @@ -420,8 +445,8 @@ function PMA_DBI_affected_rows($link = null, $get_from_cache = true) * returns metainfo for fields in $result * * @todo preserve orignal flags value - * @param object mysqli result $result - * @return array meta info for fields in $result + * @param mysqli_result $result + * @return array meta info for fields in $result */ function PMA_DBI_get_fields_meta($result) { @@ -499,8 +524,8 @@ function PMA_DBI_get_fields_meta($result) /** * return number of fields in given $result * - * @param object mysqli result $result - * @return integer field count + * @param mysqli_result $result + * @return integer field count */ function PMA_DBI_num_fields($result) { @@ -510,9 +535,9 @@ function PMA_DBI_num_fields($result) /** * returns the length of the given field $i in $result * - * @param object mysqli result $result - * @param integer $i field - * @return integer length of field + * @param mysqli_result $result + * @param integer $i field + * @return integer length of field */ function PMA_DBI_field_len($result, $i) { @@ -522,9 +547,9 @@ function PMA_DBI_field_len($result, $i) /** * returns name of $i. field in $result * - * @param object mysqli result $result - * @param integer $i field - * @return string name of $i. field in $result + * @param mysqli_result $result + * @param integer $i field + * @return string name of $i. field in $result */ function PMA_DBI_field_name($result, $i) { @@ -534,9 +559,9 @@ function PMA_DBI_field_name($result, $i) /** * returns concatenated string of human readable field flags * - * @param object mysqli result $result - * @param integer $i field - * @return string field flags + * @param mysqli_result $result + * @param integer $i field + * @return string field flags */ function PMA_DBI_field_flags($result, $i) {
hooks/post-receive