blob: 027d01ed08e8809816df22e785bd5afd479e285a (
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
62
63
64
65
66
|
<?php
require_once 'DB.php';
/*
** Setup a database connection:
*/
$db_handle = DB::connect($db_url);
if (DB::isError($db_handle)) {
die ("Database problem: ". $db_handle->getMessage());
}
$db_handle->setFetchMode(DB_FETCHMODE_ASSOC);
function db_query($sql, $debug = 0) {
global $db_handle;
$result = $db_handle->query($sql);
if ($debug) {
print "<p>query: $sql<br />"; // error:". $result->getMessage() ."</p>";
}
if (DB::isError($result)) {
watchdog("error", "database: ". $result->getMessage() ."\nquery: ". htmlspecialchars($sql));
}
return $result;
}
function db_fetch_object($result) {
if ($result) {
return $result->fetchRow(DB_FETCHMODE_OBJECT);
}
}
function db_fetch_array($result) {
if ($result) {
return $result->fetchRow(DB_FETCHMODE_ASSOC);
}
}
function db_num_rows($result) {
if ($result) {
return $result->numRows($result);
}
}
function db_result($result, $field = 0) {
if ($result) {
$tmp = $result->fetchRow(DB_FETCHMODE_ORDERED);
return $tmp[$field];
}
}
function db_error($result) {
global $db_handle;
if (DB::isError($db_handle)) {
return 1;
}
return 0;
}
?>
|