|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This is an old PHP4 database abstraction class. It has be rewritten to use |
|
4
|
|
|
* a singleton of PEARs MDB2. |
|
5
|
|
|
*/ |
|
6
|
|
|
require_once 'MDB2.php'; |
|
7
|
|
|
|
|
8
|
|
|
class DB_Sql |
|
9
|
|
|
{ |
|
10
|
|
|
var $db; |
|
11
|
|
|
var $row; |
|
12
|
|
|
var $result; |
|
13
|
|
|
|
|
14
|
|
|
function DB_Sql($dbhost = '', $dbuser = '', $dbpass = '', $dbname = '') |
|
|
|
|
|
|
15
|
|
|
{ |
|
16
|
|
|
if (empty($dbhost) OR empty($dbuser) OR empty($dbpass) OR empty($dbname)) { |
|
|
|
|
|
|
17
|
|
|
$this->db = MDB2::singleton(DB_DSN); |
|
18
|
|
|
} else { |
|
19
|
|
|
$this->db = MDB2::singleton('mysql://' . $dbuser . ':' . $dbpass . '@' . $dbhost . '/' . $dbname); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
if (PEAR::isError($this->db)) { |
|
23
|
|
|
die($this->db->getMessage() . ' ' . $this->db->getUserInfo()); |
|
|
|
|
|
|
24
|
|
|
} |
|
25
|
|
|
$this->db->query('SET NAMES utf8'); |
|
26
|
|
|
$this->db->setOption('portability', MDB2_PORTABILITY_NONE); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
View Code Duplication |
function query($SQL) |
|
|
|
|
|
|
30
|
|
|
{ |
|
31
|
|
|
$this->result = $this->db->query($SQL); |
|
32
|
|
|
if (PEAR::isError($this->result)) { |
|
33
|
|
|
die($this->result->getMessage() . ' ' . $this->result->getUserInfo()); |
|
|
|
|
|
|
34
|
|
|
} |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
View Code Duplication |
function exec($SQL) |
|
|
|
|
|
|
38
|
|
|
{ |
|
39
|
|
|
$this->result = $this->db->exec($SQL); |
|
40
|
|
|
if (PEAR::isError($this->result)) { |
|
41
|
|
|
die($this->result->getMessage() . ' ' . $this->result->getUserInfo()); |
|
|
|
|
|
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
$this->result->free(); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
View Code Duplication |
function nextRecord() |
|
|
|
|
|
|
48
|
|
|
{ |
|
49
|
|
|
// Gennemsøger recordset. |
|
50
|
|
|
// Går videre til næste post hver gang den kaldes. |
|
51
|
|
|
// Returnere true så længe der er en post |
|
52
|
|
|
// while($db->next_record()) { |
|
|
|
|
|
|
53
|
|
|
$this->row = $this->result->fetchRow(MDB2_FETCHMODE_ASSOC); |
|
54
|
|
|
if (PEAR::isError($this->row)) { |
|
55
|
|
|
die($this->row->getMessage() . '' . $this->row->getUserInfo()); |
|
|
|
|
|
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
return($this->row); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
function affectedRows() |
|
62
|
|
|
{ |
|
63
|
|
|
// returnere antallet af berørte rækker ved INSERT, UPDATE, DELETE |
|
64
|
|
|
// print($db->affected_rows()); |
|
|
|
|
|
|
65
|
|
|
|
|
66
|
|
|
return($this->db->_affectedRows(NULL)); |
|
|
|
|
|
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
function f($name) |
|
70
|
|
|
{ |
|
71
|
|
|
// Returnere værdien fra feltet med navet som er angivet. |
|
72
|
|
|
// Print($db->f("felt")); |
|
|
|
|
|
|
73
|
|
|
return($this->row[$name]); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
function free() |
|
77
|
|
|
{ |
|
78
|
|
|
// Frigør hukommelse til resultatet |
|
79
|
|
|
// $db->free(); |
|
|
|
|
|
|
80
|
|
|
$this->result->free(); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
function insertedId() |
|
84
|
|
|
{ |
|
85
|
|
|
// Returnere det id som lige er blevet indsat |
|
86
|
|
|
// $sidste_id = $db->inserted_id(); |
|
|
|
|
|
|
87
|
|
|
|
|
88
|
|
|
return($this->db->lastInsertID()); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
function numRows() |
|
92
|
|
|
{ |
|
93
|
|
|
// Returnere antallet af rækker |
|
94
|
|
|
// print($db->num_rows()); |
|
|
|
|
|
|
95
|
|
|
|
|
96
|
|
|
return($this->result->numRows()); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
function escape($value) |
|
100
|
|
|
{ |
|
101
|
|
|
return mysql_escape_string($value); |
|
|
|
|
|
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
function quote($value, $type) |
|
105
|
|
|
{ |
|
106
|
|
|
return $this->db->quote($value, $type); |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|