123456789101112131415161718192021222324252627282930 |
- <?php
- require_once('config.php');
- class DB {
- private $connection;
- public function select($sql) {
- $this->connect();
- $result = mysql_query($sql, $this->connection);
- if(!$result) {
- throw new Exception("DB exception: " . mysql_error($this->connection) . " on query " . $sql);
- }
- $selectResult = array();
- while($row = mysql_fetch_assoc($result)) {
- $selectResult[] = $row;
- }
- return $selectResult;
- }
- private function connect() {
- if(!$this->connection) {
- $this->connection = mysql_connect(DB_HOST, DB_USER, DB_PASS);
- if(!$this->connection) {
- throw new Exception("DB exception: Unable to connect to the database.");
- }
- mysql_select_db(DB_NAME, $this->connection);
- if(!$this->connection) {
- throw new Exception("DB exception: " . mysql_error($connect) . " Could not select database.");
- }
- }
- }
- }
|