creole suggested changes to handle encodings
Jean-Christophe Michel <jc.michel-/aRvmaKoZxNWk0Htik3J/[email protected]> Mon, 18 Apr 2005 22:14:39 +0200
| Newsgroups | gmane.comp.lib.binarycloud.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi,
Hans, I hope you're still reading.
I'm setting up a config to use unicode (utf-8) as internal encoding with
php, and therefore I had to change a little some Creole classes to
handle encoding.
The main idea is to have one more optional param to define the db
internal encoding. Iconv is then used to automatically convert from db
encoding to php's encoding, and back when data is passed to creole.
Works here with mysql (iso-8859-1) / php + iconv (utf-8).
Is there encoding handling in creole for php5 ?
If not, why ?
Here is the diff:
Index: binarycloud/creole/drivers/mysql/MySQLPreparedStatement.php
===================================================================
--- binarycloud/creole/drivers/mysql/MySQLPreparedStatement.php
(revision 8487)
+++ binarycloud/creole/drivers/mysql/MySQLPreparedStatement.php (working
copy)
@@ -44,6 +44,9 @@
*/
function escape($str)
{
+ if (isset($this->conn->dsn['encoding'])) {
+ $str = iconv($this->conn->dsn['output_encoding'],
$this->conn->dsn['encoding'] . '//TRANSLIT', $str);
+ }
return mysql_escape_string($str);
}
Index: binarycloud/creole/drivers/mysql/MySQLResultSet.php
===================================================================
--- binarycloud/creole/drivers/mysql/MySQLResultSet.php (revision 8487)
+++ binarycloud/creole/drivers/mysql/MySQLResultSet.php (working copy)
@@ -121,7 +121,12 @@
return false;
}
if ($this->fields[$idx] === null) { return null; }
- return (string) $this->fields[$idx];
+
+ if (isset($this->conn->dsn['encoding'])) {
+ return iconv($this->conn->dsn['encoding'],
$this->conn->dsn['output_encoding'] . '//TRANSLIT', (string)
$this->fields[$idx]);
+ } else {
+ return (string) $this->fields[$idx];
+ }
}
/**
Index: binarycloud/creole/drivers/mysql/MySQLConnection.php
===================================================================
--- binarycloud/creole/drivers/mysql/MySQLConnection.php
(revision 8487)
+++ binarycloud/creole/drivers/mysql/MySQLConnection.php (working
copy)
@@ -118,6 +118,10 @@
// fix to allow calls to different databases in the same script
$this->database = $dsninfo['database'];
+
+ // copy internal encoding into $dsn to avoid calling $i18n in
each getString()
+ $i18n =& I18n::getInstance();
+ $this->dsn['output_encoding'] = $i18n->getOutputCharacterEncoding();
}
$this->dblink = $conn;
--
Jean-Christophe Michel
_______________________________________________
dev mailing list
dev-PnctHDZWAvB/Cz2I37pSEPZ4XP/[email protected]
http://lists.binarycloud.com/mailman/listinfo/dev