From 9f982cb310fdcb1758116953b0f63875392060b4 Mon Sep 17 00:00:00 2001
From: David Grudl
Date: Wed, 4 Aug 2010 15:35:34 +0200
Subject: [PATCH] MySQL, MySQLi & PostgreSql drivers: default character set is
'utf8' (BC break)
---
dibi/drivers/mysql.php | 3 ++-
dibi/drivers/mysqli.php | 3 ++-
dibi/drivers/postgre.php | 3 ++-
examples/connecting-to-databases.php | 3 +--
4 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/dibi/drivers/mysql.php b/dibi/drivers/mysql.php
index 057d9995..fa044685 100644
--- a/dibi/drivers/mysql.php
+++ b/dibi/drivers/mysql.php
@@ -22,7 +22,7 @@
* - password (or pass)
* - database => the database name to select
* - flags (int) => driver specific constants (MYSQL_CLIENT_*)
- * - charset => character encoding to set
+ * - charset => character encoding to set (default is utf8)
* - persistent (bool) => try to find a persistent link?
* - unbuffered (bool) => sends query without fetching and buffering the result rows automatically?
* - sqlmode => see http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html
@@ -74,6 +74,7 @@ class DibiMySqlDriver extends DibiObject implements IDibiDriver, IDibiResultDriv
} else {
// default values
DibiConnection::alias($config, 'flags', 'options');
+ if (!isset($config['charset'])) $config['charset'] = 'utf8';
if (!isset($config['username'])) $config['username'] = ini_get('mysql.default_user');
if (!isset($config['password'])) $config['password'] = ini_get('mysql.default_password');
if (!isset($config['host'])) {
diff --git a/dibi/drivers/mysqli.php b/dibi/drivers/mysqli.php
index 07f7009b..7cc22e8f 100644
--- a/dibi/drivers/mysqli.php
+++ b/dibi/drivers/mysqli.php
@@ -23,7 +23,7 @@
* - database => the database name to select
* - options (array) => array of driver specific constants (MYSQLI_*) and values {@see mysqli_options}
* - flags (int) => driver specific constants (MYSQLI_CLIENT_*) {@see mysqli_real_connect}
- * - charset => character encoding to set
+ * - charset => character encoding to set (default is utf8)
* - persistent (bool) => try to find a persistent link?
* - unbuffered (bool) => sends query without fetching and buffering the result rows automatically?
* - sqlmode => see http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html
@@ -75,6 +75,7 @@ class DibiMySqliDriver extends DibiObject implements IDibiDriver, IDibiResultDri
} else {
// default values
+ if (!isset($config['charset'])) $config['charset'] = 'utf8';
if (!isset($config['username'])) $config['username'] = ini_get('mysqli.default_user');
if (!isset($config['password'])) $config['password'] = ini_get('mysqli.default_pw');
if (!isset($config['socket'])) $config['socket'] = ini_get('mysqli.default_socket');
diff --git a/dibi/drivers/postgre.php b/dibi/drivers/postgre.php
index 3570e5cf..23404630 100644
--- a/dibi/drivers/postgre.php
+++ b/dibi/drivers/postgre.php
@@ -18,7 +18,7 @@
* - host, hostaddr, port, dbname, user, password, connect_timeout, options, sslmode, service => see PostgreSQL API
* - string => or use connection string
* - schema => the schema search path
- * - charset => character encoding to set
+ * - charset => character encoding to set (default is utf8)
* - persistent (bool) => try to find a persistent link?
* - resource (resource) => existing connection resource
* - lazy, profiler, result, substitutes, ... => see DibiConnection options
@@ -62,6 +62,7 @@ class DibiPostgreDriver extends DibiObject implements IDibiDriver, IDibiResultDr
$this->connection = $config['resource'];
} else {
+ if (!isset($config['charset'])) $config['charset'] = 'utf8';
if (isset($config['string'])) {
$string = $config['string'];
} else {
diff --git a/examples/connecting-to-databases.php b/examples/connecting-to-databases.php
index 5db2c76d..922f86f8 100644
--- a/examples/connecting-to-databases.php
+++ b/examples/connecting-to-databases.php
@@ -45,7 +45,7 @@ echo "
\n";
// connects to MySQL using DSN
echo 'Connecting to MySQL: ';
try {
- dibi::connect('driver=mysql&host=localhost&username=root&password=xxx&database=test&charset=utf8');
+ dibi::connect('driver=mysql&host=localhost&username=root&password=xxx&database=test&charset=cp1250');
echo 'OK';
} catch (DibiException $e) {
@@ -65,7 +65,6 @@ try {
'username' => 'root',
'password' => 'xxx',
'database' => 'dibi',
- 'charset' => 'utf8',
'options' => array(
MYSQLI_OPT_CONNECT_TIMEOUT => 30
),