Closed (fixed)
Project:
Drupal core
Version:
4.6.0
Component:
database system
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
12 Jul 2005 at 16:15 UTC
Updated:
15 Aug 2006 at 16:22 UTC
There is no feature to specify any database connection encoding after connecting to a database in the db_connect function in database.mysql.inc neather in database.pgsql.inc. For this reason I would add a new variable to the sitewide settings.php named :
$db_after_connect_sql
This variable could specify SQL command(s) to be executed right after the connection to the database. Example:
$db_after_connect_sql = "SET NAMES 'utf-8';SET CHARACTER SET utf8";
This would set the encoding to UTF-8 for every SQL command on MySQL 4.1.x. As a result the db_connect function should be modified to the following:
function db_connect($url) {
global $db_after_connect_sql;
$url = parse_url($url);
// Allow for non-standard MySQL port.
if (isset($url['port'])) {
$url['host'] = $url['host'] .':'. $url['port'];
}
$connection = mysql_connect($url['host'], $url['user'], $url['pass'], TRUE) or die(mysql_error());
mysql_select_db(substr($url['path'], 1)) or die('unable to select database');
if (!empty($db_after_connect_sql) && $commands = explode(';', $db_after_connect_sql)) {
foreach($commands as $val) {
mysql_query($val, $connection);
}
}
return $connection;
}According to the previous code, the database.pgsql.inc should be modified similarly.
Comments
Comment #1
magico commentedhttp://drupal.org/node/8408
http://drupal.org/node/26990
http://drupal.org/node/68118