blob: 843cb270af95856e5949e741b75fee09f47a8b5f (
plain)
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
|
<?
/*
* These functions build the foundation for accessing the database:
* it is a general database abstraction layer suitable for several
* databases. Currently, the only supported database is MySQL but
* it should be straightforward to port it to any other database:
* just adjust the handlers to your needs.
*/
function db_connect() {
global $dbhost, $dbuname, $dbpass, $dbname;
mysql_pconnect($dbhost, $dbuname, $dbpass) or die(mysql_Error());
mysql_select_db($dbname) or die ("Unable to select database");
// NOTE: we are using a persistent connection!
}
function db_insert($query, $debug = false) {
// NOTE:
// add spam- and/or flood-checks
db_query($query, $debug);
}
function db_query($query, $debug = false) {
### perform query:
$qid = mysql_query($query);
### debug output (if required):
if ($debug || empty($qid)) print "<PRE>query: ". htmlspecialchars($query) ."<BR>error message: ". mysql_error() ."</PRE>";
if (empty($qid)) watchdog(3, "error: ". mysql_error() ."<BR>query: ". htmlspecialchars($query) ."");
### return result from query:
return $qid;
}
function db_fetch_object($qid) {
if ($qid) return mysql_fetch_object($qid);
}
function db_num_rows($qid) {
if ($qid) return mysql_num_rows($qid);
}
function db_fetch_row($qid) {
if ($qid) return mysql_fetch_row($qid);
}
function db_fetch_array($qid) {
if ($qid) return mysql_fetch_array($qid);
}
function db_result($qid, $field) {
if ($qid) return mysql_result($qid, $field);
}
#
# Automatically connect to database:
#
db_connect();
?>
|