| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- namespace Config {
- require_once 'Settings.class.php';
- class Database {
- // database credentials
- private $host;
- private $db_name = "iimt_mathcloud";
- private $username = "newuser";
- private $password = "password";
- //
- protected $cnx = null;
- /**
- *
- */
- public function __construct($name) {
- $this->db_name = $name;
- $this->host = Settings::getDatabaseHostname();
- }
-
- /**
- * Get the database connection.
- */
- public function getConnection() {
- if ($this->cnx == null) {
- try {
- $this->cnx = new \PDO("mysql:host=" . $this->host . ";dbname=" . $this->db_name, $this->username, $this->password, array(\PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8'"));
- }
- catch(PDOException $e){
- throw new Exception($e->getMessage());
- }
- }
- return $this->cnx;
- }
- /**
- * Get the database connection (admin).
- */
- public function getAdminConnection() {
- if ($this->cnx == null) {
- try {
- $this->cnx = new \PDO("mysql:host=" . $this->host . ";dbname=" . $this->db_name."_admin", $this->username, $this->password, array(\PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8'"));
- }
- catch(PDOException $e){
- throw new Exception($e->getMessage());
- }
- }
- return $this->cnx;
- }
- /**
- * Get the database connection (audit).
- */
- public function getAuditConnection() {
- if ($this->cnx == null) {
- try {
- $this->cnx = new \PDO("mysql:host=" . $this->host . ";dbname=" . $this->db_name."_audit", $this->username, $this->password, array(\PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8'"));
- }
- catch(PDOException $e){
- throw new Exception($e->getMessage());
- }
- }
- return $this->cnx;
- }
- }
- }
- ?>
|