Newer
Older
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
function db_connect($source) {
global $__db;
$__db = $source;
}
function db_input($what) {
return sprintf("'%8.8s'", md5($what));
}
function db_query($sql) {
global $__db;
return $__db->query($sql);
}
function db_fetch_row($res) {
return $res->fetch_row();
}
function db_fetch_array($res) {
return $res->fetch_array();
}
function db_affected_row() {
global $__db;
return $__db->affected_rows;
}
function db_insert_id() {
global $__db;
return $__db->insert_id;
}
function db_num_rows($res) {
return $res->num_rows();
}
class MockDbSource {
var $insert_id = 1;
var $affected_rows = 1;
var $data;
function __construct($data=array()) {
$this->data = $data;
}
function query($sql) {
$hash = md5($sql);
if (!isset($this->data[$sql]))
print ($hash.": No data found:\n".$sql."\n");
return new MockDbCursor($this->data[$hash] ?: array());
}
function addRecordset($hash, &$data) {
$this->data[$hash] = $data;
}
}
class MockDbCursor {
var $data;
function __construct($data) {
$this->data = $data;
}
function fetch_row() {
list($i, $row) = each($this->data);
return $row;
}
function fetch_array() {
list($i, $row) = each($this->data);
return $row;
}
function num_rows() {
return count($this->data);
}
}