gtk-mysql-database-driver
Gesponsorde koppelingen
PHP script bestanden
Code (php)
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
//-------------------------------------------------
// Onze database class
//-------------------------------------------------
class db_driver {
var $obj = array();
var $fetch_object ;
var $fetch_row = array();
var $connection_id ;
var $query_id ;
var $query = "" ;
//---------------------------------------------
// Onze constructor (maakt SQL connectie)
//---------------------------------------------
function db_driver() {
$this->obj = array('USER' => 'gebruikersnaam',
'PASS' => 'wachtwoord',
'HOST' => 'server',
'DATA' => 'database',
);
$this->connection_id = @mysql_connect($this->obj['HOST'], $this->obj['USER'], $this->obj['PASS']);
if (!$this->connection_id) {
$this->db_error('NO_CONNECT');
}
$db = @mysql_select_db($this->obj['DATA']);
if (!$db) {
$this->db_error('NO_DB');
}
}
//---------------------------------------------
// SQL query uitvoeren
//---------------------------------------------
function query($query) {
$this->query = $query;
$this->query_id = @mysql_query($query);
if (!$this->query_id) {
$this->db_error('BAD_QUERY');
}
}
//---------------------------------------------
// Onze mysql_fetch_row()
//---------------------------------------------
function fetch_row($query_id = "") {
if ($query_id == "") {
$query_id = $this->query_id;
}
$this->fetch_row = mysql_fetch_array($query_id, MYSQL_ASSOC);
return $this->fetch_row;
}
//---------------------------------------------
// Onze mysql_fetch_object()
//---------------------------------------------
function fetch_object($query_id = "") {
if ($query_id == "") {
$query_id = $this->query_id;
}
$this->fetch_object = mysql_fetch_object($query_id);
return $this->fetch_object;
}
//---------------------------------------------
// Onze mysql_free_result()
//---------------------------------------------
function free_result($query_id="") {
if ($query_id == "") {
$query_id = $this->query_id;
}
@mysql_free_result($query_id);
}
//---------------------------------------------
// Database connectie sluiten
//---------------------------------------------
function close_db() {
return @mysql_close($this->connection_id);
}
//---------------------------------------------
// Onze database error handler
//---------------------------------------------
function db_error($err_code) {
$errorcodes = array('NO_CONNECT' => 'Connectie naar MySQL gefaalt',
'NO_DB' => 'Juiste database selecteren gefaalt',
'BAD_QUERY' => 'Foute MySQL query',
'DEFAULT' => 'Basis error, Onbekend type',
);
if (!array_key_exists($err_code, $errorcodes)) {
$err_code = 'DEFAULT';
}
$errno = mysql_errno();
$err = mysql_error();
print "Fatale error mysql error: ";
print $err_code;
print "\nBeschrijving van error:";
print $errorcodes[ $err_code ];
print "\n\nMysql error nummer: ";
print $errno;
print "\nMysql gaf de volgende error terug:\n";
print $err;
if ($err_code == 'BAD_QUERY') {
print "\nQuery:";
print $this->query;
}
print "\n\nUitvoeren programma gestopt.\n";
print "-----------------------------------------";
print "\nDatabase connectie gesloten\n";
$this->close_db();
print "--------------EINDE-ERROR:{$err_code}----\n\n";
Gtk::main();
}
} //einde db_driver class
?>
//-------------------------------------------------
// Onze database class
//-------------------------------------------------
class db_driver {
var $obj = array();
var $fetch_object ;
var $fetch_row = array();
var $connection_id ;
var $query_id ;
var $query = "" ;
//---------------------------------------------
// Onze constructor (maakt SQL connectie)
//---------------------------------------------
function db_driver() {
$this->obj = array('USER' => 'gebruikersnaam',
'PASS' => 'wachtwoord',
'HOST' => 'server',
'DATA' => 'database',
);
$this->connection_id = @mysql_connect($this->obj['HOST'], $this->obj['USER'], $this->obj['PASS']);
if (!$this->connection_id) {
$this->db_error('NO_CONNECT');
}
$db = @mysql_select_db($this->obj['DATA']);
if (!$db) {
$this->db_error('NO_DB');
}
}
//---------------------------------------------
// SQL query uitvoeren
//---------------------------------------------
function query($query) {
$this->query = $query;
$this->query_id = @mysql_query($query);
if (!$this->query_id) {
$this->db_error('BAD_QUERY');
}
}
//---------------------------------------------
// Onze mysql_fetch_row()
//---------------------------------------------
function fetch_row($query_id = "") {
if ($query_id == "") {
$query_id = $this->query_id;
}
$this->fetch_row = mysql_fetch_array($query_id, MYSQL_ASSOC);
return $this->fetch_row;
}
//---------------------------------------------
// Onze mysql_fetch_object()
//---------------------------------------------
function fetch_object($query_id = "") {
if ($query_id == "") {
$query_id = $this->query_id;
}
$this->fetch_object = mysql_fetch_object($query_id);
return $this->fetch_object;
}
//---------------------------------------------
// Onze mysql_free_result()
//---------------------------------------------
function free_result($query_id="") {
if ($query_id == "") {
$query_id = $this->query_id;
}
@mysql_free_result($query_id);
}
//---------------------------------------------
// Database connectie sluiten
//---------------------------------------------
function close_db() {
return @mysql_close($this->connection_id);
}
//---------------------------------------------
// Onze database error handler
//---------------------------------------------
function db_error($err_code) {
$errorcodes = array('NO_CONNECT' => 'Connectie naar MySQL gefaalt',
'NO_DB' => 'Juiste database selecteren gefaalt',
'BAD_QUERY' => 'Foute MySQL query',
'DEFAULT' => 'Basis error, Onbekend type',
);
if (!array_key_exists($err_code, $errorcodes)) {
$err_code = 'DEFAULT';
}
$errno = mysql_errno();
$err = mysql_error();
print "Fatale error mysql error: ";
print $err_code;
print "\nBeschrijving van error:";
print $errorcodes[ $err_code ];
print "\n\nMysql error nummer: ";
print $errno;
print "\nMysql gaf de volgende error terug:\n";
print $err;
if ($err_code == 'BAD_QUERY') {
print "\nQuery:";
print $this->query;
}
print "\n\nUitvoeren programma gestopt.\n";
print "-----------------------------------------";
print "\nDatabase connectie gesloten\n";
$this->close_db();
print "--------------EINDE-ERROR:{$err_code}----\n\n";
Gtk::main();
}
} //einde db_driver class
?>