(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.3     $db_conf = $this->$conf->get("db");
30 pjaol 1.2     mysql_select_db($db_conf['dbname'], $this->$conf->get("dbh"));
31 pjaol 1.3 
32               return mysql_query($sql, $this->$conf->get("dbh"))
33           	 or die("cannot insert |". $sql."| ".mysql_error());
34 pjaol 1.1   }
35           	
36             function sel ($sql) 
37             {
38 pjaol 1.2 
39               $db_conf = $this->$conf->get("db");
40 pjaol 1.1     
41               $this->checkConn();
42               $array = array();
43 pjaol 1.3 
44 pjaol 1.2     mysql_select_db($db_conf['dbname'],$this->$conf->get("dbh")) 
45 pjaol 1.1 	or die("cannot select db ".$db_conf['dbname']." ".mysql_error());
46 pjaol 1.3 
47 pjaol 1.2     $results = mysql_query($sql, $this->$conf->get("dbh")) 
48 pjaol 1.1 	or die("bad select $sql " . mysql_error());
49 pjaol 1.3 
50 pjaol 1.1     while($row = mysql_fetch_assoc($results)) {
51                 $array[]=$row;
52               }
53 pjaol 1.3 
54 pjaol 1.1     mysql_free_result($results);
55               $this->disconnect();
56               return $array;
57             }
58           
59             function del ($sql) {
60               $this->checkConn();
61 pjaol 1.2     mysql_query($sql, $this->$conf->get("dbh"));
62 pjaol 1.1   }
63           
64             function disconnect () {
65 pjaol 1.2     $conn = $this->$conf->get("dbh");
66 pjaol 1.1     mysql_close($conn);
67 pjaol 1.2     $this->$conf->set("dbh", 0);
68 pjaol 1.1   }
69           }
70           ?>

cvsadmin
Powered by
ViewCVS 0.9.2