|
From: FlorinCB <ory...@us...> - 2008-07-20 02:41:45
|
Update of /cvsroot/mxbb/core/includes/db In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv14020 Modified Files: mysql.php mysql4.php mysqli.php postgres.php Log Message: upgrade for utf-8 languages support like greek and romanian Index: mysql.php =================================================================== RCS file: /cvsroot/mxbb/core/includes/db/mysql.php,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** mysql.php 7 Mar 2008 00:59:02 -0000 1.15 --- mysql.php 20 Jul 2008 02:41:41 -0000 1.16 *************** *** 37,45 **** var $mysql_version; var $multi_insert = true; /** * Connect to server ! * @public */ ! function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false) { $this->persistency = $persistency; --- 37,46 ---- var $mysql_version; var $multi_insert = true; + /** * Connect to server ! * @access public */ ! function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false, $new_link = false) { $this->persistency = $persistency; *************** *** 48,57 **** $this->dbname = $database; ! $this->db_connect_id = ($this->persistency) ? @mysql_pconnect($this->server, $this->user, $sqlpassword) : @mysql_connect($this->server, $this->user, $sqlpassword); if ($this->db_connect_id && $this->dbname != '') { ! if (@mysql_select_db($this->dbname)) { return $this->db_connect_id; } --- 49,97 ---- $this->dbname = $database; ! $this->sql_layer = 'mysql4'; ! ! $this->db_connect_id = ($this->persistency) ? @mysql_pconnect($this->server, $this->user, $sqlpassword, $new_link) : @mysql_connect($this->server, $this->user, $sqlpassword, $new_link); if ($this->db_connect_id && $this->dbname != '') { ! if (@mysql_select_db($this->dbname, $this->db_connect_id)) { + // Determine what version we are using and if it natively supports UNICODE + $this->mysql_version = mysql_get_server_info($this->db_connect_id); + + if (version_compare($this->mysql_version, '4.1.3', '>=')) + { + @mysql_query("SET NAMES 'utf8'", $this->db_connect_id); + // enforce strict mode on databases that support it + if (version_compare($this->mysql_version, '5.0.2', '>=')) + { + $result = @mysql_query('SELECT @@session.sql_mode AS sql_mode', $this->db_connect_id); + $row = @mysql_fetch_assoc($result); + @mysql_free_result($result); + $modes = array_map('trim', explode(',', $row['sql_mode'])); + + // TRADITIONAL includes STRICT_ALL_TABLES and STRICT_TRANS_TABLES + if (!in_array('TRADITIONAL', $modes)) + { + if (!in_array('STRICT_ALL_TABLES', $modes)) + { + $modes[] = 'STRICT_ALL_TABLES'; + } + + if (!in_array('STRICT_TRANS_TABLES', $modes)) + { + $modes[] = 'STRICT_TRANS_TABLES'; + } + } + + $mode = implode(',', $modes); + @mysql_query("SET SESSION sql_mode='{$mode}'", $this->db_connect_id); + } + } + else if (version_compare($this->mysql_version, '4.0.0', '<')) + { + $this->sql_layer = 'mysql'; + } + return $this->db_connect_id; } *************** *** 61,64 **** --- 101,105 ---- } + /** * Version information about used database Index: mysql4.php =================================================================== RCS file: /cvsroot/mxbb/core/includes/db/mysql4.php,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** mysql4.php 7 Mar 2008 00:59:03 -0000 1.15 --- mysql4.php 20 Jul 2008 02:41:41 -0000 1.16 *************** *** 43,47 **** * Connect to server */ ! function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false) { $this->persistency = $persistency; --- 43,51 ---- * Connect to server */ ! /** ! * Connect to server ! * @access public ! */ ! function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false, $new_link = false) { $this->persistency = $persistency; *************** *** 50,59 **** $this->dbname = $database; ! $this->db_connect_id = ($this->persistency) ? @mysql_pconnect($this->server, $this->user, $sqlpassword) : @mysql_connect($this->server, $this->user, $sqlpassword); if ($this->db_connect_id && $this->dbname != '') { ! if (@mysql_select_db($this->dbname)) { return $this->db_connect_id; } --- 54,102 ---- $this->dbname = $database; ! $this->sql_layer = 'mysql4'; ! ! $this->db_connect_id = ($this->persistency) ? @mysql_pconnect($this->server, $this->user, $sqlpassword, $new_link) : @mysql_connect($this->server, $this->user, $sqlpassword, $new_link); if ($this->db_connect_id && $this->dbname != '') { ! if (@mysql_select_db($this->dbname, $this->db_connect_id)) { + // Determine what version we are using and if it natively supports UNICODE + $this->mysql_version = mysql_get_server_info($this->db_connect_id); + + if (version_compare($this->mysql_version, '4.1.3', '>=')) + { + @mysql_query("SET NAMES 'utf8'", $this->db_connect_id); + // enforce strict mode on databases that support it + if (version_compare($this->mysql_version, '5.0.2', '>=')) + { + $result = @mysql_query('SELECT @@session.sql_mode AS sql_mode', $this->db_connect_id); + $row = @mysql_fetch_assoc($result); + @mysql_free_result($result); + $modes = array_map('trim', explode(',', $row['sql_mode'])); + + // TRADITIONAL includes STRICT_ALL_TABLES and STRICT_TRANS_TABLES + if (!in_array('TRADITIONAL', $modes)) + { + if (!in_array('STRICT_ALL_TABLES', $modes)) + { + $modes[] = 'STRICT_ALL_TABLES'; + } + + if (!in_array('STRICT_TRANS_TABLES', $modes)) + { + $modes[] = 'STRICT_TRANS_TABLES'; + } + } + + $mode = implode(',', $modes); + @mysql_query("SET SESSION sql_mode='{$mode}'", $this->db_connect_id); + } + } + else if (version_compare($this->mysql_version, '4.0.0', '<')) + { + $this->sql_layer = 'mysql'; + } + return $this->db_connect_id; } Index: mysqli.php =================================================================== RCS file: /cvsroot/mxbb/core/includes/db/mysqli.php,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** mysqli.php 7 Mar 2008 00:59:03 -0000 1.15 --- mysqli.php 20 Jul 2008 02:41:41 -0000 1.16 *************** *** 37,58 **** { var $multi_insert = true; /** * Connect to server */ ! function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false) { $this->persistency = $persistency; $this->user = $sqluser; ! $this->server = $sqlserver . (($port) ? ':' . $port : ''); $this->dbname = $database; ! $this->db_connect_id = ($this->persistency) ? @mysqli_pconnect($this->server, $this->user, $sqlpassword) : @mysqli_connect($this->server, $this->user, $sqlpassword); if ($this->db_connect_id && $this->dbname != '') { ! if (@mysqli_select_db($this->db_connect_id, $this->dbname)) { ! return $this->db_connect_id; } } --- 37,84 ---- { var $multi_insert = true; + /** * Connect to server */ ! function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false , $new_link = false) { $this->persistency = $persistency; $this->user = $sqluser; ! $this->server = $sqlserver; $this->dbname = $database; + $port = (!$port) ? NULL : $port; ! // Persistant connections not supported by the mysqli extension? ! $this->db_connect_id = @mysqli_connect($this->server, $this->user, $sqlpassword, $this->dbname, $port); if ($this->db_connect_id && $this->dbname != '') { ! @mysqli_query($this->db_connect_id, "SET NAMES 'utf8'"); ! // enforce strict mode on databases that support it ! if (mysqli_get_server_version($this->db_connect_id) >= 50002) { ! $result = @mysqli_query($this->db_connect_id, 'SELECT @@session.sql_mode AS sql_mode'); ! $row = @mysqli_fetch_assoc($result); ! @mysqli_free_result($result); ! $modes = array_map('trim', explode(',', $row['sql_mode'])); ! ! // TRADITIONAL includes STRICT_ALL_TABLES and STRICT_TRANS_TABLES ! if (!in_array('TRADITIONAL', $modes)) ! { ! if (!in_array('STRICT_ALL_TABLES', $modes)) ! { ! $modes[] = 'STRICT_ALL_TABLES'; ! } ! ! if (!in_array('STRICT_TRANS_TABLES', $modes)) ! { ! $modes[] = 'STRICT_TRANS_TABLES'; ! } ! } ! ! $mode = implode(',', $modes); ! @mysqli_query($this->db_connect_id, "SET SESSION sql_mode='{$mode}'"); } + return $this->db_connect_id; } Index: postgres.php =================================================================== RCS file: /cvsroot/mxbb/core/includes/db/postgres.php,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** postgres.php 7 Mar 2008 00:59:03 -0000 1.15 --- postgres.php 20 Jul 2008 02:41:41 -0000 1.16 *************** *** 41,56 **** * Connect to server */ ! function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false) { ! $this->connect_string = ''; if ($sqluser) { ! $this->connect_string .= "user=$sqluser "; } if ($sqlpassword) { ! $this->connect_string .= "password=$sqlpassword "; } --- 41,56 ---- * Connect to server */ ! function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false, $new_link = false) { ! $connect_string = ''; if ($sqluser) { ! $connect_string .= "user=$sqluser "; } if ($sqlpassword) { ! $connect_string .= "password=$sqlpassword "; } *************** *** 59,90 **** if (strpos($sqlserver, ':') !== false) { ! list($sqlserver, $sqlport) = explode(':', $sqlserver); ! $this->connect_string .= "host=$sqlserver port=$sqlport "; } - else - { - if ($sqlserver != "localhost") - { - $this->connect_string .= "host=$sqlserver "; - } ! if ($port) ! { ! $this->connect_string .= "port=$port "; ! } } } if ($database) { $this->dbname = $database; ! $this->connect_string .= "dbname=$database"; } $this->persistency = $persistency; ! $this->db_connect_id = ($this->persistency) ? @pg_pconnect($this->connect_string) : @pg_connect($this->connect_string); ! return ($this->db_connect_id) ? $this->db_connect_id : $this->sql_error(''); } --- 59,124 ---- if (strpos($sqlserver, ':') !== false) { ! list($sqlserver, $port) = explode(':', $sqlserver); } ! if ($sqlserver !== 'localhost') ! { ! $connect_string .= "host=$sqlserver "; ! } ! ! if ($port) ! { ! $connect_string .= "port=$port "; } } + $schema = ''; + if ($database) { $this->dbname = $database; ! if (strpos($database, '.') !== false) ! { ! list($database, $schema) = explode('.', $database); ! } ! $connect_string .= "dbname=$database"; } $this->persistency = $persistency; ! $this->db_connect_id = ($this->persistency) ? @pg_pconnect($connect_string, $new_link) : @pg_connect($connect_string, $new_link); ! if ($this->db_connect_id) ! { ! // determine what version of PostgreSQL is running, we can be more efficient if they are running 8.2+ ! if (version_compare(PHP_VERSION, '5.0.0', '>=')) ! { ! $this->pgsql_version = @pg_parameter_status($this->db_connect_id, 'server_version'); ! } ! else ! { ! $query_id = @pg_query($this->db_connect_id, 'SELECT VERSION()'); ! $row = @pg_fetch_assoc($query_id, null); ! @pg_free_result($query_id); ! ! if (!empty($row['version'])) ! { ! $this->pgsql_version = substr($row['version'], 10); ! } ! } ! ! if (!empty($this->pgsql_version) && $this->pgsql_version[0] >= '8' && $this->pgsql_version[2] >= '2') ! { ! $this->multi_insert = true; ! } ! ! if ($schema !== '') ! { ! @pg_query($this->db_connect_id, 'SET search_path TO ' . $schema); ! } ! return $this->db_connect_id; ! } ! ! return $this->sql_error(''); } |