-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path_class.dba.inc.php
More file actions
executable file
·131 lines (127 loc) · 4.23 KB
/
_class.dba.inc.php
File metadata and controls
executable file
·131 lines (127 loc) · 4.23 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
//this is our mysql-class
class dba
{
var $database = "";
var $link_id = 0;
var $query_id = 0;
var $record = array();
var $errdesc = "";
var $errno = 0;
var $show_error = 1;
var $server = "";
var $user = "";
var $password = "";
// $dba->connect(); - create an mysql-link
function connect()
{
if (0 == $this->link_id) {
$this->link_id = @mysqli_connect($this->server, $this->user, $this->password, $this->database);
if (!$this->link_id) {
$this->print_error("Link-ID == false, connect failed");
}
}
}
// $dba->geterrdesc(); - return the mysql-error
function geterrdesc()
{
$this->error = mysqli_error($this->link_id );
return $this->error;
}
// $dba->geterrno(); - return the mysql-error number
function geterrno()
{
$this->errno = mysqli_errno($this->link_id );
return $this->errno;
}
// $dba->select_db( $database); - select a database to work with
function select_db($database = "")
{
if ($database!="") {
$this->database = $database;
}
if (!@mysqli_select_db($this->link_id, $this->database)) {
$this->print_error("Can not use database ".$this->database);
}
}
// $dba->query( $query_string); - executes your query
function query($query_string)
{
$this->query_id = mysqli_query($this->link_id, $query_string);
if (!$this->query_id) {
$this->print_error("Invalid SQL-Query: ".$query_string);
@mysqli_query($this->link_id, "ROLLBACK");
die();
}
return $this->query_id;
}
// $dba->fetch_assoc( $query_id); - fetches another row of results
function fetch_assoc($query_id = -1)
{
if ($query_id != -1) {
$this->query_id=$query_id;
}
$this->record = mysqli_fetch_assoc( $this->query_id);
return $this->record;
}
// $dba->free_result( $query_id); - ???
function free_result($query_id = -1)
{
if ($query_id != -1) {
$this->query_id = $query_id;
}
return @mysqli_free_result($this->link_id, $this->query_id);
}
// $dba->query_first( $query_string); - ???
function query_first($query_string)
{
$this->query($query_string);
$returnarray=$this->fetch_assoc($this->query_id);
#$this->free_result($this->query_id);
return $returnarray;
}
// $dba->num_rows( $query_id); - returns the number of rows in the query
function num_rows($query_id = -1)
{
if ($query_id != -1) {
$this->query_id = $query_id;
}
return mysqli_num_rows($this->query_id);
}
// $dba->insert_id(); - Liefert die ID einer vorherigen INSERT-Operation
function insert_id()
{
return mysqli_insert_id($this->link_id);
}
// $dba->GetPrimaryCol( $table);
function GetPrimaryCol($table)
{
$result = $this->query("DESCRIBE ".$table);
$row = $this->fetch_assoc($result);
//row[0] holds the primary fieldname. get it and return it
return $row[0];
}
// $dba->print_error( $msg); - prints an error
function print_error($msg)
{
$this->errdesc = mysqli_error($this->link_id );
$this->errno = mysqli_errno($this->link_id );
$message = "<table width=\"50%\"><tr><td bgcolor=\"red\">\n";
$message .= "Database error: $msg\n<br>";
$message .= "mysql error: $this->errdesc\n<br>";
$message .= "mysql error number: $this->errno\n<br>";
$message .= "Date: ".date("d.m.Y @ H:i")."\n<br>";
$message .= "Script: ".getenv("REQUEST_URI")."\n<br>";
$message .= "Referer: ".getenv("HTTP_REFERER")."\n<br><br>";
if ($this->show_error) {
$message = "$message";
} else {
$message = "\n<!-- $message -->\n";
}
print "<html><head><title>Error!</title></head><body>\n";
print "<font face=\"Verdana\" size=\"2\">";
print $message;
print "</font>\n";
print "</body></html>";
}
}