[pLog-svn] r2294 - plog/branches/plog-1.0.2/class/database/adodb/drivers

jondaley at devel.plogworld.net jondaley at devel.plogworld.net
Fri Jul 8 13:46:30 GMT 2005


Author: jondaley
Date: 2005-07-08 13:46:29 +0000 (Fri, 08 Jul 2005)
New Revision: 2294

Modified:
   plog/branches/plog-1.0.2/class/database/adodb/drivers/adodb-mysql.inc.php
Log:
added adodb patch.  http://bugs.plogworld.net/view.php?id=590

Modified: plog/branches/plog-1.0.2/class/database/adodb/drivers/adodb-mysql.inc.php
===================================================================
--- plog/branches/plog-1.0.2/class/database/adodb/drivers/adodb-mysql.inc.php	2005-07-08 09:15:32 UTC (rev 2293)
+++ plog/branches/plog-1.0.2/class/database/adodb/drivers/adodb-mysql.inc.php	2005-07-08 13:46:29 UTC (rev 2294)
@@ -351,6 +351,14 @@
 			$this->_connectionID = mysql_connect($argHostname,$argUsername,$argPassword);
 	
 		if ($this->_connectionID === false) return false;
+
+        if ($this->_isSupportUtf8() && $argDatabasename) {
+            $dbEncoding = $this->_getDbDefaultEncoding($argDatabasename);
+            if ($dbEncoding) {
+                mysql_query("SET NAMES $dbEncoding", $this->_connectionID);
+            }
+        }
+                                                    
 		if ($argDatabasename) return $this->SelectDB($argDatabasename);
 		return true;	
 	}
@@ -364,6 +372,14 @@
 			$this->_connectionID = mysql_pconnect($argHostname,$argUsername,$argPassword);
 		if ($this->_connectionID === false) return false;
 		if ($this->autoRollback) $this->RollbackTrans();
+        
+        if ($this->_isSupportUtf8() && $argDatabasename) {
+            $dbEncoding = $this->_getDbDefaultEncoding($argDatabasename);
+            if ($dbEncoding) {
+                mysql_query("SET NAMES $dbEncoding", $this->_connectionID);
+            }
+        }
+                                     
 		if ($argDatabasename) return $this->SelectDB($argDatabasename);
 		return true;	
 	}
@@ -373,9 +389,43 @@
 		$this->forceNewConnect = true;
 		return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename);
 	}
-	
- 	function &MetaColumns($table) 
-	{
+
+    function _isSupportUtf8() {
+            // check mysql version first. Version lower than 4.1 doesn't support utf8
+        $serverVersion = mysql_get_server_info($this->_connectionID);
+        $version = explode('.', $serverVersion);
+        if ($version[0] < 4) return false;
+        if ( ($version[0] == 4) && ($version[1] == 0) ) return false;
+        
+            // check if utf8 support was compiled in
+        $result = mysql_query("SHOW CHARACTER SET like 'utf8'", $this->_connectionID);
+        if (mysql_num_rows($result) > 0) {
+            return true;
+        }
+        return false;
+    }
+    
+    function _getDbDefaultEncoding($argDatabasename){
+        if (!$argDatabasename) {
+            return false;
+        }
+        
+            // We use a SHOW CREATE DATABASE command to show the original
+            // SQL character set when DB was created.
+        $result = mysql_query("SHOW CREATE DATABASE $argDatabasename", $this->_connectionID);
+        if (mysql_num_rows($result) < 0 ) {
+                // The specified db name is wrong!
+            return false;
+        }
+        $dbInfo = mysql_fetch_row($result);
+        $pattern = '/40100 DEFAULT CHARACTER SET (\w+) /';
+        if ( (preg_match($pattern, $dbInfo[1], $match) > 0) ) {
+            return $match[1];
+        }
+        return false;
+    }
+    
+ 	function &MetaColumns($table){
 		global $ADODB_FETCH_MODE;
 		$save = $ADODB_FETCH_MODE;
 		$ADODB_FETCH_MODE = ADODB_FETCH_NUM;




More information about the pLog-svn mailing list