1 pjaol 1.1 <?php
2
3 class db_handle {
4
5 function conn ()
6 {
7 $conf = Conf::instance();
8 $db_conf = $conf->get("db");
9 $conn = mysql_pconnect($db_conf['host'],$db_conf['user'],$db_conf['passwd']);
10 $conf->set("dbh",$conn);
11 }
12
13 function checkConn () {
14 $conf = Conf::instance();
15 if(! $conf->get("dbh")) {
16 conn();
17 }
18 }
19 function ins ($sql) {
20 $conf = Conf::instance();
21 checkConn();
22 pjaol 1.1 disconnect();
23 return mysql_query($sql, $conf->get("dbh"));
24 }
25
26 function sel ($sql)
27 {
28 $conf = Conf::instance();
29 checkConn();
30 $array = array();
31 $results = mysql_query($sql, $conf->get("dbh"));
32 while($row = mysql_fetch_assoc($results)) {
33 $array[]=$row;
34 }
35 mysql_free_result($results);
36 disconnect();
37 return $array;
38 }
39
40 function del ($sql) {
41 $conf = Conf::instance();
42 checkConn();
43 pjaol 1.1 mysql_query($sql, $conf->get("dbh"));
44 }
45
46 function disconnect () {
47 $conf = Conf::instance();
48 $conn = $conf->get("dbh");
49 mysql_close($conn);
50 $conf->set("dbh", 0);
51 }
52 }
53 ?>
|