From: Filipus K. <ch...@gm...> - 2010-10-05 04:56:56
|
Hi Nyloth, are you sure only the client charset needs to be defined? If the database is latin1, the "connection" encoding settings will differ. character_set_connection will be latin1. This causes some kind of corruption (a recoverable one) in BLOBs when they receive non-ASCII characters, which come back incorrectly. You can try this uploading a non-trivial file to a file gallery on Tiki 5.3 or newer and trying to recover it, on a latin1 database. > Revision:*27399* > http://tikiwiki.svn.sourceforge.net/tikiwiki/?rev=*27399*&view=rev <http://tikiwiki.svn.sourceforge.net/tikiwiki/?rev=27399&view=rev> > Author: nyloth > Date: 2010-05-31 13:43:11 +0000 (Mon, 31 May 2010) > > Log Message: > ----------- > [FIX] Deeper change to fix PDO charset problem. Now uses UTF-8 for clean installs and upgrades from 3.x and > before. Upgrades from 4.0 remain unfixed to avoid data corruption/double encoding. > The MySQL charset client can be changed by setting it inside db/local.php (e.g. $client_charset='utf8'; ) > Please test - will roll-back before release if this makes things worse. > > Compared to the previous fix from Jonny, this fix is in the same spirit but : > - uses PDO for the installer, instead of AdoDB, because AdoDB is not 100% fine regarding charsets (AdoDB > will use the charset defined in MySQL my.cnf config, which may be wrong too) > - uses "SET CHARACTER SET" instead of "SET NAMES" because only the client charset has to be defined > - also test on $db_version, but don't fallback on "$TWV = new TWVersion;" because this will always be the > current version (5.x) of the code, not the version of the previous code > > Modified Paths: > -------------- > branches/5.x/db/tiki-db-pdo.php > branches/5.x/installer/tiki-installer.php > branches/5.x/lib/core/lib/TikiDb/Pdo.php > branches/5.x/lib/core/lib/TikiDb.php > branches/5.x/tiki-install.php > > Modified: branches/5.x/db/tiki-db-pdo.php > =================================================================== > --- branches/5.x/db/tiki-db-pdo.php 2010-05-31 13:32:28 UTC (rev 27398) > +++ branches/5.x/db/tiki-db-pdo.php 2010-05-31 13:43:11 UTC (rev*27399*) > @@ -26,22 +26,49 @@ > } > } > > -if (isset($tiki_pdo_utf8)&& $tiki_pdo_utf8) { > - $extra_params = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'); > -} else { > - $extra_params = array(); > -} > - > try { > - //$dbTiki = new PDO("$db_tiki:host=$host_tiki;dbname=$dbs_tiki", $user_tiki, $pass_tiki); > - $dbTiki = new PDO("$db_tiki:$db_hoststring;dbname=$dbs_tiki", $user_tiki, $pass_tiki, $extra_params); > - $dbTiki->setAttribute(PDO::ATTR_CASE,PDO::CASE_NATURAL); > - $dbTiki->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_WARNING); > - $dbTiki->setAttribute(PDO::ATTR_ORACLE_NULLS,PDO::NULL_EMPTY_STRING); > +/* > + $pdoDriverOptions = empty( $client_charset ) > + ? array( PDO::MYSQL_ATTR_READ_DEFAULT_GROUP => true ) > + : array( PDO::MYSQL_ATTR_INIT_COMMAND => "SET CHARACTER SET $client_charset" ); > > + $dbTiki = new PDO("$db_tiki:$db_hoststring;dbname=$dbs_tiki", $user_tiki, $pass_tiki, $pdoDriverOptions); > +*/ > require_once 'lib/core/lib/TikiDb/Pdo.php'; > - TikiDb::set( new TikiDb_Pdo( $dbTiki ) ); > > + $conn = false; > + if ( ! isset( $client_charset ) ) { > + // This case should not happen if Tiki was correctly updated with the web installer > + > + $dbTiki = new PDO( "$db_tiki:$db_hoststring;dbname=$dbs_tiki", $user_tiki, $pass_tiki ); > + $dbTiki->setAttribute(PDO::ATTR_CASE,PDO::CASE_NATURAL); > + $dbTiki->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_WARNING); > + $dbTiki->setAttribute(PDO::ATTR_ORACLE_NULLS,PDO::NULL_EMPTY_STRING); > + TikiDb::set( new TikiDb_Pdo( $dbTiki ) ); > + > + $tempDb = TikiDb::get(); > + $dbCharsetVariables = $tempDb->getCharsetVariables(); > + $client_charset = $tempDb->detectBestClientCharset( $dbCharsetVariables ); > + unset( $tempDb ); > + > + $conn = ( ! empty($client_charset)&& $client_charset == > $dbCharsetVariables['character_set_client'] ); > + } > + if ( empty( $client_charset ) ) { > + $client_charset = 'utf8'; > + } > + > + if ( ! $conn ) { > + $dbTiki = new PDO( "$db_tiki:$db_hoststring;dbname=$dbs_tiki", $user_tiki, $pass_tiki, > + array( PDO::MYSQL_ATTR_INIT_COMMAND => "SET CHARACTER SET $client_charset" ) > + ); > + > + $dbTiki->setAttribute(PDO::ATTR_CASE,PDO::CASE_NATURAL); > + $dbTiki->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_WARNING); > + $dbTiki->setAttribute(PDO::ATTR_ORACLE_NULLS,PDO::NULL_EMPTY_STRING); > + > + TikiDb::set( new TikiDb_Pdo( $dbTiki ) ); > + } > + > } catch( PDOException $e ) { > require_once 'setup_smarty.php'; > > Modified: branches/5.x/installer/tiki-installer.php > =================================================================== > --- branches/5.x/installer/tiki-installer.php 2010-05-31 13:32:28 UTC (rev 27398) > +++ branches/5.x/installer/tiki-installer.php 2010-05-31 13:43:11 UTC (rev*27399*) > @@ -20,6 +20,7 @@ > require_once ( 'lib/smarty/libs/Smarty.class.php'); > require_once ('installer/installlib.php'); > > +$dbTiki = false; > $commands = array(); > @ini_set('magic_quotes_runtime',0); > > @@ -57,14 +58,10 @@ > return $installer->tableExists('tiki_pages_translation_bits'); > } > > -function write_local_php($dbb_tiki, $host_tiki, $user_tiki, $pass_tiki, $dbs_tiki, > $dbversion_tiki='') { > - global $local, $db_tiki, $tiki_pdo_utf8; > - > +function write_local_php($dbb_tiki, $host_tiki, $user_tiki, $pass_tiki, $dbs_tiki, > $client_charset = '', $api_tiki = '', $dbversion_tiki = '5.0') { > + global $local; > + global $db_tiki; > if ($dbs_tiki&& $user_tiki) { > - if (empty($dbversion_tiki)) { > - $TWV = new TWVersion; > - $dbversion_tiki = $TWV->getBaseVersion(); > - } > $db_tiki = addslashes($dbb_tiki); > $host_tiki = addslashes($host_tiki); > $user_tiki = addslashes($user_tiki); > @@ -74,11 +71,14 @@ > $filetowrite = "<?php\n"; > $filetowrite .= "\$db_tiki='" . $db_tiki . "';\n"; > $filetowrite .= "\$dbversion_tiki='" . $dbversion_tiki . "';\n"; > - $filetowrite .= "\$tiki_pdo_utf8=" . ($tiki_pdo_utf8 ? 'true' : 'false') . ";\n"; > $filetowrite .= "\$host_tiki='" . $host_tiki . "';\n"; > $filetowrite .= "\$user_tiki='" . $user_tiki . "';\n"; > $filetowrite .= "\$pass_tiki='" . $pass_tiki . "';\n"; > $filetowrite .= "\$dbs_tiki='" . $dbs_tiki . "';\n"; > + if ( ! empty( $api_tiki ) ) { > + $filetowrite .= "\$api_tiki='" . $api_tiki . "';\n"; > + } > + $filetowrite .= "\$client_charset='" . "$client_charset" . "';\n"; > fwrite($fw, $filetowrite); > fclose($fw); > } > @@ -333,29 +333,28 @@ > > > > -function has_admin() { > - // Try to see if we have an admin account > - global $dbTiki; > - global $admin_acc; > +// Try to see if we have an admin account > +function has_admin( $dbTiki, $api_tiki ) { > $query = "select hash from users_users where login='admin'"; > + $res = false; > > - @$result = $dbTiki->Execute($query); > + if ( $api_tiki == 'pdo' ) { > + if ( @ ( $result = $dbTiki->prepare($query) )&& $result->execute() ) { > + $res = $result->fetch( PDO::FETCH_ASSOC ); > + } > + } else { > + if ( @ ( $result = $dbTiki->Execute($query) )&& $result->numRows() ) { > + $res = $result->fetchRow(); > + } > + } > > - if (!$result) { > - $admin_acc = 'n'; > - } else { > - if ($result->numRows()) { > - $res = $result->fetchRow(); > + if ( $res&& isset( $res['hash'] ) ) { > + $admin_acc = 'y'; > + } else { > + $admin_acc = 'n'; > + } > > - if (isset($res['hash'])) { > - $admin_acc = 'y'; > - } else { > - $admin_acc = 'n'; > - } > - } else { > - $admin_acc = 'n'; > - } > - } > + return $admin_acc; > } > > function get_admin_email( $dbTiki ) { > @@ -403,6 +402,53 @@ > } > } > > +function initTikiDB(&$api,&$driver, $host, $user, $pass, $dbname, $client_charset,&$dbTiki ) { > + global $tikifeedback; > + $dbcon = false; > + > + if ( ( isset($api)&& $api == 'adodb' ) || ! extension_loaded('pdo') ) { > + $api = 'adodb'; > + $dbTiki = ADONewConnection( $driver ); > + $db = new TikiDb_Adodb( $dbTiki ); > + if ( $dbcon = (bool) @$dbTiki->Connect($host, $user, $pass, $dbname) ) { > + $tikifeedback[] = array( 'num' => 1, 'mes' => $dbTiki->ErrorMsg() ); > + } > + } else { > + $dbcon = true; > + $db_hoststring = "host=$host"; > + > + if ( $driver == 'mysqli' ) { > + $driver = 'mysql'; > + if ( isset( $socket_tiki ) ) { > + $db_hoststring = "unix_socket=$socket_tiki"; > + } > + } > + > + try { > + if ( empty( $client_charset ) ) { > + $dbTiki = new PDO( "$driver:$db_hoststring;dbname=$dbname", $user, $pass ); > + } else { > + $dbTiki = new PDO( "$driver:$db_hoststring;dbname=$dbname", $user, $pass, > + array( PDO::MYSQL_ATTR_INIT_COMMAND => "SET CHARACTER SET $client_charset" ) > + ); > + } > + } catch ( PDOException $e ) { > + $dbcon = false; > + $tikifeedback[] = array( 'num' => 1, 'mes'=> $e->getMessage() ); > + } > + if ( $dbcon ) { > + $db = new TikiDb_Pdo( $dbTiki ); > + } > + } > + > + if ( $dbcon ) { > + $db->setErrorHandler(new InstallerDatabaseErrorHandler); > + TikiDb::set($db); > + } > + > + return $dbcon; > +} > + > // ----------------------------------------------------------------------------- > // end of functions .. now starts the processing > > @@ -530,65 +576,72 @@ > > // next block checks if there is a local.php and if we can connect through this. > // sets $dbcon to false if there is no valid local.php > -if (!file_exists($local)) { > - $dbcon = false; > - $smarty->assign('dbcon', 'n'); > - $tiki_pdo_utf8 = true; // clean install, use UTF-8 > -} else { > +$dbcon = false; > +if ( file_exists($local) ) { > // include the file to get the variables > + $default_api_tiki = $api_tiki; > + $api_tiki = ''; > + unset($client_charset); > include $local; > + if ( ! $client_charset_forced = isset($client_charset) ) { > + $client_charset = ''; > + } > + $previousDbApi = $api_tiki; > + if ( empty( $api_tiki ) ) { > + $api_tiki_forced = false; > + $api_tiki = $default_api_tiki; > + if ( ! empty( $dbversion_tiki )&& $dbversion_tiki[0]< 4 ) { > + $previousDbApi = 'adodb'; // AdoDB was the default DB abstraction layer before 4.0 > + } > + } else { > + $api_tiki_forced = true; > + } > + > + unset( $default_api_tiki ); > + > // In case of replication, ignore it during installer. > unset( $shadow_dbs, $shadow_user, $shadow_pass, $shadow_host ); > if ($dbversion_tiki == '1.10') { > $dbversion_tiki = '2.0'; > } > - if ($dbversion_tiki != '4.0'&& !isset($tiki_pdo_utf8)) { // don't use PDO UTF-8 to avoid double > encoding if existing data > - $tiki_pdo_utf8 = true; // unless it's an upgrade from 3.x which used ADODB and therefore existing > data is already UTF-8 > - write_local_php($db_tiki, $host_tiki, $user_tiki, $pass_tiki, $dbs_tiki); > - } > - > + > if (!isset($db_tiki)) { > // if no db is specified, use the first db that this php installation can handle > $db_tiki = reset($dbservers); > - write_local_php($db_tiki, $host_tiki, $user_tiki, $pass_tiki, $dbs_tiki); > + write_local_php($db_tiki, $host_tiki, $user_tiki, $pass_tiki, $dbs_tiki, $client_charset, > ($api_tiki_forced ? $api_tiki : ''), $dbversion_tiki); > } > > $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; > > - // avoid errors in ADONewConnection() (wrong darabase driver etc...) > - if (!isset($dbservers[$db_tiki])) { > - $dbcon = false; > - $smarty->assign('dbcon', 'n'); > - } else { > - $dbTiki = ADONewConnection($db_tiki); > - $db = new TikiDb_Adodb($dbTiki); > - $db->setErrorHandler(new InstallerDatabaseErrorHandler); > - TikiDb::set($db); > + $dbcon = false; > + if ( isset( $dbservers[$db_tiki] ) ) { // avoid errors in ADONewConnection() (wrong darabase driver etc...) > + if ( $dbcon = initTikiDB( $api_tiki, $db_tiki, $host_tiki, $user_tiki, $pass_tiki, $dbs_tiki, > $client_charset, $dbTiki ) ) { > + $smarty->assign( 'resetdb', isset($_REQUEST['reset']) ? 'y' : 'n' ); > > - if (! $test = $dbTiki->Connect($host_tiki, $user_tiki, $pass_tiki, $dbs_tiki)) { > - $dbcon = false; > - $smarty->assign('dbcon', 'n'); > - $tikifeedback[] = array('num'=>1, 'mes'=>$dbTiki->ErrorMsg()); > - } else { > - $dbcon = true; > $installer = new Installer; > $installer->setServerType($db_tiki); > - if (!isset($_REQUEST['reset'])) { > - $smarty->assign('dbcon', 'y'); > - $smarty->assign('resetdb', 'n'); > - } else { > - $smarty->assign('dbcon', 'y'); > - $smarty->assign('resetdb', 'y'); > + > + if ( ! $client_charset_forced ) { > + > + $dbCharsetVariables = $installer->getCharsetVariables(); > + $client_charset = $installer->detectBestClientCharset( $dbCharsetVariables, null, > $previousDbApi ); > + > + write_local_php($db_tiki, $host_tiki, $user_tiki, $pass_tiki, $dbs_tiki, $client_charset, > ($api_tiki_forced ? $api_tiki : ''), $dbversion_tiki); > + > + // Try to reconnect to the DB using the detected client_charset if not the same as the current one > + if ( ! empty($client_charset)&& $client_charset != > $dbCharsetVariables['character_set_client'] ) { > + $dbcon = initTikiDB( $api_tiki, $db_tiki, $host_tiki, $user_tiki, $pass_tiki, $dbs_tiki, > $client_charset, $dbTiki ); > + } > } > } > } > } > > -if ($dbcon) { > - has_admin(); > +if ( $dbcon ) { > + $admin_acc = has_admin( $dbTiki, $api_tiki ); > } > > -if ($admin_acc == 'n') { > +if ( $admin_acc == 'n' ) { > $smarty->assign('noadmin', 'y'); > } else { > $smarty->assign('noadmin', 'n'); > @@ -612,38 +665,31 @@ > ) > )&& isset($_REQUEST['dbinfo']) > ) { > - $dbTiki = ADONewConnection($_REQUEST['db']); > - $db = new TikiDb_Adodb( $dbTiki ); > - $db->setErrorHandler( new InstallerDatabaseErrorHandler ); > - TikiDb::set( $db ); > - > - // try to connect to database and write db information > - if (isset($_REQUEST['name'])&& $_REQUEST['name']) { > - if (!@$dbTiki->Connect($_REQUEST['host'], $_REQUEST['user'], $_REQUEST['pass'], > $_REQUEST['name'])) { > - $dbcon = false; > - $smarty->assign('dbcon', 'n'); > - $tikifeedback[] = array('num'=>1, 'mes'=>$dbTiki->ErrorMsg()); > - } else { > - $dbcon = true; > - $smarty->assign('dbcon', 'y'); > - write_local_php($_REQUEST['db'], $_REQUEST['host'], $_REQUEST['user'], $_REQUEST['pass'], $_REQUEST['name']); > - include $local; > - // In case of replication, ignore it during installer. > - unset( $shadow_dbs, $shadow_user, $shadow_pass, $shadow_host ); > - $installer = new Installer; > - $installer->setServerType($db_tiki); > - } > + if ( ! empty($_REQUEST['name']) ) { > + $client_charset = 'utf8'; > + $dbcon = initTikiDB( $api_tiki, $_REQUEST['db'], $_REQUEST['host'], $_REQUEST['user'], > $_REQUEST['pass'], $_REQUEST['name'], $client_charset, $dbTiki ); > + write_local_php( $_REQUEST['db'], $_REQUEST['host'], $_REQUEST['user'], $_REQUEST['pass'], > $_REQUEST['name'], $client_charset ); > + include $local; > + // In case of replication, ignore it during installer. > + unset( $shadow_dbs, $shadow_user, $shadow_pass, $shadow_host ); > + $installer = new Installer; > + $installer->setServerType($db_tiki); > } else { > $dbcon = false; > - $smarty->assign('dbcon', 'n'); > $tikifeedback[] = array('num'=>1, 'mes'=>tra("No database name specified")); > } > } > > +if ( $dbcon ) { > + $smarty->assign('dbcon', 'y'); > +} else { > + $smarty->assign('dbcon', 'n'); > +} > + > if ($dbcon) { > $has_tiki_db = has_tiki_db(); > $smarty->assign('tikidb_created', $has_tiki_db); > - $oldPerms = $dbTiki->getOne('SELECT COUNT(*) FROM `users_permissions` WHERE `permDesc` = \'Can > view categorized items\''); > + $oldPerms = $installer->getOne('SELECT COUNT(*) FROM `users_permissions` WHERE `permDesc` = \'Can > view categorized items\''); > $smarty->assign('tikidb_oldPerms', $oldPerms); > > if ($install_step == '6'&& $has_tiki_db) { > @@ -736,14 +782,6 @@ > exit; > } > > -// unused? (4.x) > -//if( isset( $_GET['lockchange'] ) ) > -//{ > -// touch( 'db/lock' ); > -// header( 'Location: tiki-change_password.php?user=admin' ); > -// exit; > -//} > - > $smarty->assign_by_ref('tikifeedback', $tikifeedback); > > $smarty->assign('metatag_robots', 'NOINDEX, NOFOLLOW'); > > Modified: branches/5.x/lib/core/lib/TikiDb/Pdo.php > =================================================================== > --- branches/5.x/lib/core/lib/TikiDb/Pdo.php 2010-05-31 13:32:28 UTC (rev 27398) > +++ branches/5.x/lib/core/lib/TikiDb/Pdo.php 2010-05-31 13:43:11 UTC (rev*27399*) > @@ -18,7 +18,7 @@ > } > > function fetchRow() { > - return array_shift($this->result); > + return is_array($this->result) ? array_shift($this->result) : 0; > } > > function numRows() { > > Modified: branches/5.x/lib/core/lib/TikiDb.php > =================================================================== > --- branches/5.x/lib/core/lib/TikiDb.php 2010-05-31 13:32:28 UTC (rev 27398) > +++ branches/5.x/lib/core/lib/TikiDb.php 2010-05-31 13:43:11 UTC (rev*27399*) > @@ -65,11 +65,18 @@ > function getOne( $query, $values = null, $reporterrors = true, $offset = 0 ) // {{{ > { > $result = $this->query( $query, $values, 1, $offset, $reporterrors ); > - $res = $result->fetchRow(); > - if (empty($res)) { > - return $res; > + > + if ( $result ) { > + $res = $result->fetchRow(); > + > + if ( empty( $res ) ) { > + return $res; > + } > + > + return reset( $res ); > } > - return reset( $res ); > + > + return false; > } // }}} > > function fetchAll( $query = null, $values = null, $numrows = -1, $offset = -1, $reporterrors = true ) // {{{ > @@ -256,4 +263,162 @@ > if (strlen($s)> 0) return "CONCAT($s)"; > else return ''; > } // }}} > + > + function getCharsetVariables() // {{{ > + { > + $return = array(); > + > + foreach ( array( 'character_set%', 'collation%' ) as $varName ) { > + $result = $this->query( "show variables like '$varName'" ); > + while ( $res = $result->fetchRow() ) { > + $return[ $res['Variable_name'] ] = $res['Value']; > + } > + } > + > + return $return; > + } // }}} > + > + function getDefaultConfigCharsets() { // {{{ > + $return = false; > + > + global $api_tiki; > + if ( $api_tiki == 'pdo' ) { > + global $local_php; > + if ( ! empty( $local_php )&& file_exists( $local_php ) ) { > + include( $local_php ); > + > + $db_hoststring = "host=$host_tiki"; > + if ( $db_tiki == 'mysqli' ) { > + $db_tiki = 'mysql'; > + if ( isset( $socket_tiki ) ) { > + $db_hoststring = "unix_socket=$socket_tiki"; > + } > + } > + > + if ( $db_tiki == 'mysql' ) { > + $return = array(); > + > + // Create another PDO connection, to use the "PDO::MYSQL_ATTR_READ_DEFAULT_GROUP" attribute, > which allows to get MySQL default config from my.cnf file > + $tmpPdo = new PDO("$db_tiki:$db_hoststring;dbname=$dbs_tiki", $user_tiki, $pass_tiki, > array(PDO::MYSQL_ATTR_READ_DEFAULT_GROUP => true) ); > + if ( $result = $tmpPdo->query( "show variables like 'character__set__%'" ) ) { > + while ( $res = $result->fetch() ) { > + $return[ $res['Variable_name'] ] = $res['Value']; > + } > + } > + } > + } > + } > + > + return $return; > + } // }}} > + > + function detectContentCharset(&$errorMsg, $dbCharsetVariables = null, > $dbDefaultConfigCharsets = null, $previousDbApi = null ) { // {{{ > + > + if ( $dbCharsetVariables === null ) { > + $dbCharsetVariables = $this->getCharsetVariables(); > + } > + if ( empty( $previousDbApi ) ) { > + $previousDbApi = $api_tiki; > + } > + > + $dbCharset = $dbCharsetVariables['character_set_database']; > + $utf8DbCharset = ( substr( strtoupper($dbCharset), 0, 3 ) == 'UTF' ); > + > + $dbConnectionCharset = $dbCharsetVariables['character_set_connection']; > + $utf8ConnectionCharset = ( substr( strtoupper($dbConnectionCharset), 0, 3 ) == 'UTF' ); > + > + if ( $previousDbApi == 'adodb'&& $api_tiki != 'adodb' ) { > + // We are updating Tiki from AdoDB to PDO abstraction layer... > + // ... this is why we have to check AdoDB Connection Charset instead > + > + if ( $dbDefaultConfigCharsets === null ) { > + $dbDefaultConfigCharsets = $this->getDefaultConfigCharsets(); > + } > + $utf8ConnectionCharset = ( substr( > strtoupper($dbDefaultConfigCharsets['character_set_connection']), 0, 3 ) == 'UTF' ); > + } > + > + if ( $utf8ConnectionCharset&& $utf8DbCharset ) { > + // FULL UTF-8 installation (UTF-8 DB + UTF-8 connection) > + return 'utf8'; > + } elseif ( $dbConnectionCharset == $dbCharset ) { > + // DB is not in UTF-8, but MySQL will try to convert on-the-fly if possible > + return $dbCharset; > + } else { > + // either DB is in UTF-8, but data is wrongly reencoded > + // or connection is in UTF-8, but DB is in another charset > + return false; > + } > + > + return false; > + } // }}} > + > + function detectBestClientCharset( $dbCharsetVariables = null, $dbDefaultConfigCharsets = null, > $previousDbApi = null ) { // {{{ > + global $api_tiki; > + > + if ( empty( $dbCharsetVariables ) ) { > + $dbCharsetVariables = $this->getCharsetVariables(); > + } > + if ( empty( $previousDbApi ) ) { > + $previousDbApi = $api_tiki; > + } > + > + $dbClientCharset = $dbCharsetVariables['character_set_client']; > + $adodbUtf8ClientCharset = $utf8ClientCharset = ( substr( strtoupper($dbClientCharset), 0, 3 ) == > 'UTF' ); > + > + if ( $previousDbApi == 'adodb'&& $api_tiki != 'adodb' ) { > + if ( $dbDefaultConfigCharsets === null ) { > + $dbDefaultConfigCharsets = $this->getDefaultConfigCharsets(); > + } > + $adodbUtf8ClientCharset = ( substr( > strtoupper($dbDefaultConfigCharsets['character_set_client']), 0, 3 ) == 'UTF' ); > + } > + > + if ( $utf8ClientCharset ) { > + // The current connection is using UTF-8 for ClientCharset > + if ( $api_tiki == 'pdo' ) { > + // The current DB abstraction layer is PDO > + if ( $previousDbApi == 'pdo' ) { > + // The data in DB has been stored using PDO > + return 'utf8'; > + } else { > + // The data in DB has been stored using AdoDB > + // (we are most probably in the upgrade process from 4.x to 5.x) > + if ( $adodbUtf8ClientCharset ) { > + // AdoDB was using an UTF-8 Client Charset > + return 'utf8'; > + } else { > + // AdoDB was using a wrong Client Charset > + return $dbDefaultConfigCharsets['character_set_client']; > + } > + } > + } else { > + // The current DB abstraction layer is AdoDB > + return 'utf8'; > + } > + } else { > + // The current connection is using a wrong Client Charset > + if ( $api_tiki == 'pdo' ) { > + // The current DB abstraction layer is PDO > + if ( $previousDbApi == 'pdo' ) { > + // The data in DB has been stored using PDO > + return $dbClientCharset; > + } else { > + // The data in DB has been stored using AdoDB > + // (we are most probably in the upgrade process from 4.x to 5.x) > + if ( $adodbUtf8ClientCharset ) { > + // AdoDB was using an UTF-8 Client Charset > + return 'utf8'; > + } else { > + // AdoDB was using a wrong Client Charset > + return $dbDefaultConfigCharsets['character_set_client']; > + } > + } > + } else { > + // The current DB abstraction layer is AdoDB > + // => ClientCharset can't be forced unless a data reencoding is done > + return $dbClientCharset; > + } > + } > + > + return false; > + } // }}} > } > > Modified: branches/5.x/tiki-install.php > =================================================================== > --- branches/5.x/tiki-install.php 2010-05-31 13:32:28 UTC (rev 27398) > +++ branches/5.x/tiki-install.php 2010-05-31 13:43:11 UTC (rev*27399*) > @@ -40,6 +40,7 @@ > session_start(); > > require_once 'lib/core/lib/TikiDb/Adodb.php'; > +require_once 'lib/core/lib/TikiDb/Pdo.php'; > |