Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
slylth committed Sep 30, 2015
2 parents 91b1cec + ce190a5 commit ed83137
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
15 changes: 8 additions & 7 deletions carl_util/db/connectDB.php
Expand Up @@ -27,14 +27,9 @@
* All parameters except for dbName are deprecated.
*
* @param string $dbName A database connector name - this maps to an entry in the XML file
* @param string $dbuser Deprecated - is now ignored
* @param string $dbpasswd Deprecated - is now ignored
* @param string $dbhost Deprecated - is now ignored
* @return resource database connection resource
*
* @todo remove the $dbuse, $dbpasswd, and $dbhost parameters entirely to remove a potential source of confusion
*/
function connectDB($dbName, $dbuser = '', $dbpasswd = '', $dbhost='')
function connectDB($dbName)
{
$db_info = get_db_credentials( $dbName );
// try to connect to server
Expand Down Expand Up @@ -71,7 +66,8 @@ function connectDB($dbName, $dbuser = '', $dbpasswd = '', $dbhost='')
}

// set character set for connection to UTF-8
mysql_set_charset("utf8", $db);
if(!empty($db_info[ 'charset' ]))
mysql_set_charset($db_info[ 'charset' ], $db);

$GLOBALS['_current_db_connection_name'] = $dbName;
return $db;
Expand Down Expand Up @@ -152,6 +148,11 @@ function get_db_credentials( $conn_name, $lack_of_creds_is_fatal = true )
$reader->read();
if ($reader->nodeType == XMLReader::TEXT) $database['host'] = $reader->value;
}
elseif ($reader->name == 'charset')
{
$reader->read();
if ($reader->nodeType == XMLReader::TEXT) $database['charset'] = $reader->value;
}
}
if ( ($reader->nodeType == XMLReader::END_ELEMENT) && ($reader->name == 'database') ) break;
}
Expand Down
2 changes: 2 additions & 0 deletions settings/dbs.xml
Expand Up @@ -7,6 +7,7 @@
<user>reason_user</user>
<password>some_password</password>
<host>127.0.0.1</host>
<charset>utf8</charset>
</database>

<database>
Expand All @@ -15,5 +16,6 @@
<user>reason_user</user>
<password>some_password</password>
<host>127.0.0.1</host>
<charset>utf8</charset>
</database>
</databases>
2 changes: 2 additions & 0 deletions settings/dbs.xml.sample
Expand Up @@ -7,6 +7,7 @@
<user>reason_user</user>
<password>some_password</password>
<host>your.mysql.hostname.or.ip.address</host>
<charset>utf8</charset>
</database>

<database>
Expand All @@ -15,5 +16,6 @@
<user>reason_user</user>
<password>some_password</password>
<host>your.mysql.hostname.or.ip.address</host>
<charset>utf8</charset>
</database>
</databases>

0 comments on commit ed83137

Please sign in to comment.