Changing Database service to accept custom db info in construct, no
longer solely relying on config constantspull/18/head^2
parent
90b1ba5705
commit
6075bc80ab
|
@ -35,17 +35,33 @@ class Database {
|
||||||
protected $num_rows_found;
|
protected $num_rows_found;
|
||||||
protected $num_rows_returned;
|
protected $num_rows_returned;
|
||||||
|
|
||||||
function __construct() {
|
function __construct($host = null, $user = null, $pass = null, $db = null) {
|
||||||
// Initizale connection
|
if($host != null && $user != null && $pass != null && $db != null) {
|
||||||
$this->link = mysql_connect(PSM_DB_HOST, PSM_DB_USER, PSM_DB_PASS);
|
$this->connect($host, $user, $pass, $db);
|
||||||
|
} elseif(defined('PSM_DB_HOST') && defined('PSM_DB_USER') && defined('PSM_DB_PASS') && defined('PSM_DB_NAME')) {
|
||||||
if (!mysql_select_db(PSM_DB_NAME, $this->link)) {
|
$this->connect(PSM_DB_HOST, PSM_DB_USER, PSM_DB_PASS, PSM_DB_NAME);
|
||||||
trigger_error(mysql_errno() . ": " . mysql_error());
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setting the utf collection
|
/**
|
||||||
mysql_query("SET NAMES utf8;", $this->getLink());
|
* Connect to the database
|
||||||
mysql_query("SET CHARACTER SET 'utf8';", $this->getLink());
|
* @param string $host
|
||||||
|
* @param string $user
|
||||||
|
* @param string $pass
|
||||||
|
* @param string $db
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
protected function connect($host, $user, $pass, $db) {
|
||||||
|
$this->link = mysql_connect($host, $user, $pass);
|
||||||
|
|
||||||
|
if (!mysql_select_db($db, $this->link)) {
|
||||||
|
trigger_error(mysql_errno() . ": " . mysql_error());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
mysql_query("SET NAMES utf8;", $this->link);
|
||||||
|
mysql_query("SET CHARACTER SET 'utf8';", $this->link);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue