3
* @package DbConnection
4
* @author Patrick Schmiedel <patrick.schmiedel@gmx.net>
5
* @author Keith Hughitt <Vincent.K.Hughitt@nasa.gov>
7
class Database_DbConnection {
8
private $host = HV_DB_HOST;
9
private $dbname = HV_DB_NAME;
10
private $user = HV_DB_USER;
11
private $password = HV_DB_PASS;
2
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
* Database connection helper
10
* @author Patrick Schmiedel <patrick.schmiedel@gmx.net>
11
* @author Keith Hughitt <keith.hughitt@nasa.gov>
12
* @license http://www.mozilla.org/MPL/MPL-1.1.html Mozilla Public License 1.1
13
* @link http://launchpad.net/helioviewer.org
16
* Database connection helper class
19
* @package Helioviewer
20
* @author Patrick Schmiedel <patrick.schmiedel@gmx.net>
21
* @author Keith Hughitt <keith.hughitt@nasa.gov>
22
* @license http://www.mozilla.org/MPL/MPL-1.1.html Mozilla Public License 1.1
23
* @link http://launchpad.net/helioviewer.org
25
class Database_DbConnection
27
private $_host = HV_DB_HOST;
28
private $_dbname = HV_DB_NAME;
29
private $_user = HV_DB_USER;
30
private $_password = HV_DB_PASS;
14
* @param string [optional] Database name
15
* @param string [optional] Database user
16
* @param string [optional] Database password
17
* @param string [optional] Database hostname
33
* Create a DbConnection instance
35
* @param string $dbname [Optional] Database name
36
* @param string $user [Optional] Database user
37
* @param string $password [Optional] Database password
38
* @param string $host [Optional] Database hostname
19
public function __construct($dbname = null, $user = null, $password = null, $host = null) {
42
public function __construct($dbname = null, $user = null, $password = null, $host = null)
24
$this->password = $password;
48
$this->_password = $password;
30
$this->dbname = $dbname;
54
$this->_dbname = $dbname;
60
* Connects to database and sets timezone to UTC
38
public function connect() {
39
if (!$this->link = mysqli_connect($this->host, $this->user, $this->password)) {
64
public function connect()
66
if (!$this->link = mysqli_connect($this->_host, $this->_user, $this->_password)) {
40
67
die('Error connecting to data base: ' . mysqli_error($this->link));
42
mysqli_select_db($this->link, $this->dbname);
69
mysqli_select_db($this->link, $this->_dbname);
43
70
mysqli_query($this->link, "SET @@session.time_zone = '+00:00'");
76
* @param string $query SQL query
49
78
* @return mixed Query result
51
public function query($query) {
80
public function query($query)
52
82
$result = mysqli_query($this->link, $query);
54
84
die("Error executing query:<br>\n$query <br>\n " . mysqli_error($this->link));