-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UTF8 #7
Comments
You can declare your own PDO object with the correct charset and then pass it into sparrow. See http://stackoverflow.com/questions/4361459/php-pdo-charset-set-names |
Thanks for your reply. So I initizialize the database in this way:
where $config is: [ So is only enough to change config in order to change database engine. |
For example this is for mysqli, mysql and pdo: switch ($db['type']) {
case 'mysqli':
$this->db = new mysqli(
$db['hostname'],
$db['username'],
$db['password'],
$db['database']
);
if ($this->db->connect_error) {
throw new Exception('Connection error: '.$this->db->connect_error);
}
/* Change character set */
if (! $this->db->set_charset($db['charset'])) {
throw new Exception("Error loading character set utf8: %s\n", $this->db->error);
}
break;
case 'mysql':
$this->db = mysql_connect(
$db['hostname'],
$db['username'],
$db['password']
);
if (!$this->db) {
throw new Exception('Connection error: '.mysql_error());
}
/* Change character set */
mysql_set_charset($db['charset'], $this->db);
mysql_select_db($db['database'], $this->db);
break;
case 'pdomysql':
$dsn = sprintf(
'mysql:host=%s;port=%d;dbname=%s;charset=%s', /* Change character set */
$db['hostname'],
isset($db['port']) ? $db['port'] : 3306,
$db['database'],
$db['charset'] /* Change character set */
);
$this->db = new PDO($dsn, $db['username'], $db['password']);
$db['type'] = 'pdo';
break;
}
|
For pgsql, I think that is http://php.net/manual/en/function.pg-set-client-encoding.php Not sure also for sqlite and sqlite3. And in last, for pdomysql and pdosqlite, I think that only way is to run query: $this->db->('SET NAMES UTF8'); I guess why not add this on sparrow? thanks |
Hi,
I just noticed, that sparrow (i'm using pdo) doesn't display special characters correctly (noticed with äöü).
I fixed this by changing line 667 to:
$this->db = new PDO($dsn, $db['username'], $db['password'], array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
By the way: I really appreciate your work and started using Flight as well on a project!
Update: I just made a pull request :)
The text was updated successfully, but these errors were encountered: