-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.inc.default
63 lines (49 loc) · 1.79 KB
/
db.inc.default
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
class dbconn {
var $handle;
var $results;
var $dbname;
function dbconn() {
$this->dbname = "dbname";
$this->handle = mysqli_connect("127.0.0.1", "username", "password");
if (!$this->handle) trigger_error("Could not connect to database", E_USER_ERROR);
mysqli_select_db($this->handle, $this->dbname);
}
function query($qstring) {
if ($GLOBALS['dbtrace']) echo "DB Query: $qstring<br>\n";
$newkey = md5(microtime().posix_getpid());
$this->results[$newkey] = array("query" => $qstring, "result" => mysqli_query($this->handle, $qstring));
if ($this->results[$newkey]["result"]) {
if (strcasecmp(strtok($this->results[$newkey]["query"], " "), "SELECT")) $this->results[$newkey]["rows"] = mysqli_affected_rows($this->handle);
else $this->results[$newkey]["rows"] = mysqli_num_rows($this->results[$newkey]["result"]);
if (!strcasecmp(strtok($this->results[$newkey]["query"], " "), "INSERT")) $this->results[$newkey]["newid"] = mysqli_insert_id($this->handle);
else $this->results[$newkey]["newid"] = 0;
}
else $this->results[$newkey]["rows"] = 0;
return $newkey;
}
function fetch_row($resultid, $rtype = MYSQL_BOTH) {
return mysqli_fetch_array($this->results[$resultid]["result"], $rtype);
}
function row_count($resultid) {
return $this->results[$resultid]["rows"];
}
function new_id($resultid) {
return $this->results[$resultid]["newid"];
}
function delete_query($resultid) {
unset($this->results[$resultid]);
}
function escape($query) {
return mysqli_real_escape_string ($this->handle, $query);
}
function get_fields($table) {
if ($GLOBALS['dbtrace']) echo "DB Getfields: $table<br>\n";
$query = mysqli_query($this->handle, "SELECT * FROM $table LIMIT 1");
$retval = array();
$finfo = mysqli_fetch_fields($query);
foreach ($finfo as $field) $retval[] = $field->name;
return $retval;
}
}
?>