* MySQL: got mysqli extension working and make it default for EGroupware, as mysql is now officially deprecated, existing installs need to be switched manually in header.inc.php or Setup >> Manage header

prefering mysqli for new installs
This commit is contained in:
Ralf Becker 2013-05-27 09:37:13 +00:00
parent d46bd621ae
commit e72d937e19
5 changed files with 232 additions and 219 deletions

View File

@ -24,7 +24,7 @@ $config = array(
'domain' => 'default', 'domain' => 'default',
'config_user' => 'admin', 'config_user' => 'admin',
'config_passwd' => randomstring(), 'config_passwd' => randomstring(),
'db_type' => 'mysql', 'db_type' => 'mysqli',
'db_host' => 'localhost', 'db_host' => 'localhost',
'db_port' => 3306, 'db_port' => 3306,
'db_name' => 'egroupware', 'db_name' => 'egroupware',

View File

@ -121,6 +121,19 @@ class ADODB_mysqli extends ADOConnection {
return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename); return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename);
} }
/**
* Check if we are connected
*
* Reimplemented as check in ADOConnection::IsConnected will allways return true, as _connectionID is mysqli object!
*
* @see ADOConnection::IsConnected()
* @return boolean
*/
function IsConnected()
{
return $this->_connectionID && @mysqli_ping($this->_connectionID);
}
function IfNull( $field, $ifNull ) function IfNull( $field, $ifNull )
{ {
return " IFNULL($field, $ifNull) "; // if MySQL return " IFNULL($field, $ifNull) "; // if MySQL
@ -692,13 +705,18 @@ class ADODB_mysqli extends ADOConnection {
* *
* mysqli_set_charset is php5.1+, the query used here works since mysql4.1 * mysqli_set_charset is php5.1+, the query used here works since mysql4.1
* *
* mysqli_set_charset is strongly prefered, as mysqli_real_escape only uses charset set this way!
*
* @param string $charset_name * @param string $charset_name
* @return boolean true on success, false otherwise * @return boolean true on success, false otherwise
*/ */
function SetCharSet($charset_name) function SetCharSet($charset_name)
{ {
$mysql_charset = isset($this->charset2mysql[$charset_name]) ? $this->charset2mysql[$charset_name] : $charset_name; $mysql_charset = isset($this->charset2mysql[$charset_name]) ? $this->charset2mysql[$charset_name] : $charset_name;
if (!mysqli_query($this->_connectionID,'SET NAMES '.$this->qstr($mysql_charset))) return false; if (function_exists('mysqli_set_charset')) {
if (!mysqli_set_charset($this->_connectionID,$mysql_charset)) return false;
}
elseif (!mysqli_query($this->_connectionID,'SET NAMES '.$this->qstr($mysql_charset))) return false;
if ($this->GetCharSet()) { if ($this->GetCharSet()) {
return $this->charSet == $charset_name || $this->charset2mysql[$this->charSet] == $charset_name; return $this->charSet == $charset_name || $this->charset2mysql[$this->charSet] == $charset_name;
} }

View File

@ -418,14 +418,10 @@ class egw_db
return null; // in case error-reporting = 'no' return null; // in case error-reporting = 'no'
} }
$connect = $GLOBALS['egw_info']['server']['db_persistent'] ? 'PConnect' : 'Connect'; $connect = $GLOBALS['egw_info']['server']['db_persistent'] ? 'PConnect' : 'Connect';
if (($Ok = $this->Link_ID->$connect($Host, $User, $Password))) if (($Ok = $this->Link_ID->$connect($Host, $User, $Password, $Database)))
{ {
$this->ServerInfo = $this->Link_ID->ServerInfo(); $this->ServerInfo = $this->Link_ID->ServerInfo();
$this->set_capabilities($type,$this->ServerInfo['version']); $this->set_capabilities($type,$this->ServerInfo['version']);
if($Database)
{
$Ok = $this->Link_ID->SelectDB($Database);
}
} }
if (!$Ok) if (!$Ok)
{ {
@ -456,8 +452,7 @@ class egw_db
$this->Link_ID =& $GLOBALS['egw']->ADOdb; $this->Link_ID =& $GLOBALS['egw']->ADOdb;
} }
} }
// next ADOdb version: if (!$this->Link_ID->isConnected()) $this->Link_ID->Connect(); if (!$this->Link_ID->isConnected()) $this->Link_ID->Connect();
if (!$this->Link_ID->_connectionID) $this->Link_ID->Connect();
if ($new_connection) if ($new_connection)
{ {

View File

@ -270,7 +270,7 @@ class setup_cmd_database extends setup_cmd
* @param string $db_type='mysql' * @param string $db_type='mysql'
* @return array * @return array
*/ */
static function defaults($db_type='mysql') static function defaults($db_type='mysqli')
{ {
switch($db_type) switch($db_type)
{ {

View File

@ -26,10 +26,10 @@ class setup_header
* @var array with php-extension / ADOdb drive names => describtiv label * @var array with php-extension / ADOdb drive names => describtiv label
*/ */
var $db_fullnames = array( var $db_fullnames = array(
'mysqli' => 'MySQLi (recommended, incl. transactions)',
'mysql' => 'MySQL (deprecated)',
'mysqlt' => 'MySQL (deprecated, transactions)',
'pgsql' => 'PostgreSQL', 'pgsql' => 'PostgreSQL',
'mysql' => 'MySQL',
'mysqli' => 'MySQLi (php5)',
'mysqlt' => 'MySQL (with transactions)',
'mssql' => 'MS SQL Server', 'mssql' => 'MS SQL Server',
'odbc_mssql' => 'MS SQL Server via ODBC', 'odbc_mssql' => 'MS SQL Server via ODBC',
'oracle' => 'Oracle', 'oracle' => 'Oracle',
@ -84,7 +84,7 @@ class setup_header
function domain_defaults($user='admin',$passwd='',$supported_db=null) function domain_defaults($user='admin',$passwd='',$supported_db=null)
{ {
if (is_null($supported_db)) $supported_db = $this->check_db_support($null); if (is_null($supported_db)) $supported_db = $this->check_db_support($null);
$default_db = count($supported_db) ? $supported_db[0] : 'mysql'; $default_db = count($supported_db) ? $supported_db[0] : 'mysqli';
return array( return array(
'db_host' => 'localhost', 'db_host' => 'localhost',
@ -232,8 +232,8 @@ class setup_header
$supported_db = $detected = array(); $supported_db = $detected = array();
foreach(array( foreach(array(
// short => array(extension,func_to_check,supported_db(s)) // short => array(extension,func_to_check,supported_db(s))
'mysql' => array('mysql','mysql_connect','mysql'),
'mysqli' => array('mysql','mysqli_connect','mysqli'), 'mysqli' => array('mysql','mysqli_connect','mysqli'),
'mysql' => array('mysql','mysql_connect','mysql'),
'mysqlt' => array('mysql','mysql_connect','mysqlt'), 'mysqlt' => array('mysql','mysql_connect','mysqlt'),
'pgsql' => array('pgsql','pg_connect','pgsql'), 'pgsql' => array('pgsql','pg_connect','pgsql'),
'mssql' => array('mssql','mssql_connect','mssql'), 'mssql' => array('mssql','mssql_connect','mssql'),