Skip to content

Instantly share code, notes, and snippets.

@nojimage
Created March 12, 2010 14:14
Show Gist options
  • Save nojimage/330341 to your computer and use it in GitHub Desktop.
Save nojimage/330341 to your computer and use it in GitHub Desktop.
cakephp dbo_mysql, dbo_mysqli setEncoding() patch
diff --git a/cake/libs/model/datasources/dbo/dbo_mysql.php b/cake/libs/model/datasources/dbo/dbo_mysql.php
index 2cc215b..2730c0d 100644
--- a/cake/libs/model/datasources/dbo/dbo_mysql.php
+++ b/cake/libs/model/datasources/dbo/dbo_mysql.php
@@ -781,5 +781,20 @@ class DboMysql extends DboMysqlBase {
}
return false;
}
+
+/**
+ * Sets the database encoding
+ *
+ * @param string $enc Database encoding
+ */
+ function setEncoding($enc) {
+ if (function_exists('mysql_set_charset')) {
+ // php 5.2.3 upper support mysql_set_charset()
+ if (mysql_set_charset($enc, $this->connection)) {
+ return true;
+ }
+ }
+ return parent::setEncoding($enc);
+ }
}
?>
\ No newline at end of file
diff --git a/cake/libs/model/datasources/dbo/dbo_mysqli.php b/cake/libs/model/datasources/dbo/dbo_mysqli.php
index 8d5609b..c0feb85 100644
--- a/cake/libs/model/datasources/dbo/dbo_mysqli.php
+++ b/cake/libs/model/datasources/dbo/dbo_mysqli.php
@@ -335,5 +335,21 @@ class DboMysqli extends DboMysqlBase {
function hasResult() {
return is_object($this->_result);
}
+
+/**
+ * Sets the database encoding
+ *
+ * @param string $enc Database encoding
+ */
+ function setEncoding($enc) {
+ if (function_exists('mysqli_set_charset')) {
+ // php 5.0.5 upper support mysqli_set_charset()
+ if (mysqli_set_charset($this->connection, $enc)) {
+ return true;
+ }
+ }
+ return parent::setEncoding($enc);
+ }
+
}
?>
\ No newline at end of file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment