2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2010 */
6 /* Inclusive Design Institute */
8 /* This program is free software. You can redistribute it and/or */
9 /* modify it under the terms of the GNU General Public License */
10 /* as published by the Free Software Foundation. */
11 /************************************************************************/
14 * Root data access object
15 * Each table has a DAO class, all inherits from this class
24 static private $db; // global database connection
28 if (!isset($this->db))
30 $this->db = @mysql_connect(DB_HOST . ':' . DB_PORT, DB_USER, DB_PASSWORD);
32 die('Unable to connect to db.');
34 if (!@mysql_select_db(DB_NAME, $this->db)) {
35 die('DB connection established, but database "'.DB_NAME.'" cannot be selected.');
43 * @param $sql : SQL statment to be executed
44 * @return $rows: for 'select' sql, return retrived rows,
45 * true: for non-select sql
49 function execute($sql)
52 $result = mysql_query($sql, $this->db) or die($sql . "<br />". mysql_error());
54 // for 'select' SQL, return retrieved rows
55 if (strtolower(substr($sql, 0, 6)) == 'select')
57 if (mysql_num_rows($result) > 0) {
58 for($i = 0; $i < mysql_num_rows($result); $i++)
60 $rows[] = mysql_fetch_assoc($result);
62 mysql_free_result($result);