[ Index ] |
PHP Cross Reference of Yamoon 0.9.0 |
[Summary view] [Print] [Text view]
1 <?php 2 3 require_once "DB.php"; 4 5 /** 6 * Config.php - have all configurations for this program. 7 * It's configuration is hard coded inside the class, I'll have 8 * to change it to accept four methods: read, write, get, set. 9 * 10 * This class is used within all classes of Yamoon. 11 */ 12 13 class Config { 14 var $db; 15 var $db_host; 16 var $db_name; 17 var $db_user; 18 var $db_pass; 19 var $template_dir; 20 var $conf_dir; 21 var $mrtg_dir; 22 var $mrtg_url; 23 var $redir_timeout; 24 var $redir_timeout_error; 25 26 var $local_tz; 27 28 /** 29 * Config Constructor. Sets all config values. 30 */ 31 function Config () { 32 $this->db; 33 $this->db_host = "localhost"; 34 $this->db_name = "yamoon"; 35 $this->db_user = "root"; 36 $this->db_pass = ""; 37 $this->template_dir = "/usr/local/share/yamoon/templates"; 38 $this->conf_dir = "/usr/local/share/yamoon/conf"; 39 $this->mrtg_dir = "/srv/www/htdocs/mrtg"; 40 $this->mrtg_url = "http://localhost/mrtg"; 41 $this->redir_timeout = 1; 42 $this->redir_timeout_error = 600; 43 $this->local_tz = "Americas/Sao Paulo"; 44 } 45 46 /** 47 * Return the database. Connect to it if $this->db is empty. 48 */ 49 function getDB() { 50 if ($this->db) { 51 return $this->db; 52 } else { 53 return $this->dbConnect(); 54 } 55 } 56 57 /** 58 * Connect to a MySQL database. 59 * 60 * return $db The database handler. 61 */ 62 function dbConnect () { 63 $connectionString = "mysql://$this->db_user:$this->db_pass@$this->db_host/$this->db_name"; 64 $this->db =& DB::connect($connectionString, ""); 65 if (DB::isError($this->db)) { 66 $msg = "Error connecting to DB: ".$this->db->getMessage()."[$connectionString]"; 67 error_log($msg); 68 die($msg); 69 } 70 return $this->db; 71 } 72 73 /** 74 * Execute a query and return it's resultSet object. Call this 75 * method directly if issuing a update or delete. 76 * 77 * param $query The query to be executed (use ? instead of '$param' inside it) 78 * param $values An array with all values (one for each ? inside the query) 79 * return $res The resultSet Object 80 */ 81 function query ($query, $values=array()) { 82 // Prepare 83 $sth = $this->db->prepare($query); 84 //error_log("[$query] [$values[0], $values[1], $values[2]...]"); 85 // Execute! 86 if (!($res = $this->db->execute($sth, $values))) { 87 $this->error = "Cannot execute query [$query]"; 88 error_log($this->error); 89 return false; 90 } 91 // Error during execution 92 if (!$res || $res->code < 0) { 93 $this->error = "Error while execute query [$query]"; 94 error_log($this->error); 95 return false; 96 } 97 return $res; 98 } 99 100 /** 101 * Execute a select query and return the array of values. 102 * This method calls the query() method and fetch the object array 103 * from the resultSet returned. 104 * 105 * param $query The query to be executed (use ? instead of '$param' inside it) 106 * param $values An array with all values (one for each ? inside the query) 107 * return $rows The array with all returned objects 108 */ 109 function select ($query, $values=array()) { 110 $res = $this->query($query, $values); 111 // Return 112 $rows = array(); 113 while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) 114 array_push($rows, $row); 115 return $rows; 116 } 117 } 118 119 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sat Feb 19 17:29:53 2005 | Cross-referenced by PHPXref 0.6 |