(file) Return to mysql_conn.inc CVS log (file) (dir) Up to [Development] / gantt_manager / src / lib / db

 1 pjaol 1.1 <?php
 2           
 3           class db_handle {
 4           
 5 pjaol 1.2   private $conf;
 6           
 7             function __construct () 
 8             {
 9               $this->$conf = Conf::instance();
10             }
11 pjaol 1.1   function conn ()
12             {
13 pjaol 1.2    
14               $db_conf = $this->$conf->get("db");
15 pjaol 1.1     $conn = mysql_pconnect($db_conf['host'],$db_conf['dbuser'],$db_conf['passwd']) 
16           	or die("cannot connect ".mysql_error());
17 pjaol 1.2     $this->$conf->set("dbh",$conn);
18 pjaol 1.1   }
19           
20             function checkConn () {
21 pjaol 1.2    
22               if(! $this->$conf->get("dbh")) {
23 pjaol 1.1       $this->conn();
24               }
25             }
26             function ins ($sql) {
27 pjaol 1.2 
28 pjaol 1.1     $this->checkConn();
29 pjaol 1.2     mysql_select_db($db_conf['dbname'], $this->$conf->get("dbh"));
30               return mysql_query($sql, $this->$conf->get("dbh"));
31 pjaol 1.1   }
32           	
33             function sel ($sql) 
34             {
35 pjaol 1.2 
36               $db_conf = $this->$conf->get("db");
37 pjaol 1.1     
38               $this->checkConn();
39               $array = array();
40 pjaol 1.2     mysql_select_db($db_conf['dbname'],$this->$conf->get("dbh")) 
41 pjaol 1.1 	or die("cannot select db ".$db_conf['dbname']." ".mysql_error());
42 pjaol 1.2     $results = mysql_query($sql, $this->$conf->get("dbh")) 
43 pjaol 1.1 	or die("bad select $sql " . mysql_error());
44               while($row = mysql_fetch_assoc($results)) {
45                 $array[]=$row;
46               }
47               mysql_free_result($results);
48               $this->disconnect();
49               return $array;
50             }
51           
52             function del ($sql) {
53               $this->checkConn();
54 pjaol 1.2     mysql_query($sql, $this->$conf->get("dbh"));
55 pjaol 1.1   }
56           
57             function disconnect () {
58 pjaol 1.2     $conn = $this->$conf->get("dbh");
59 pjaol 1.1     mysql_close($conn);
60 pjaol 1.2     $this->$conf->set("dbh", 0);
61 pjaol 1.1   }
62           }
63           ?>

cvsadmin
Powered by
ViewCVS 0.9.2