Menu

[r16]: / html / util.php  Maximize  Restore  History

Download this file

167 lines (145 with data), 5.1 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<?php
/*
* Utility routines for MySQL.
*/
class MySQL_class {
var $db, $id, $result, $rows, $data, $a_rows;
var $user, $pass, $host;
/* Make sure you change the USERNAME and PASSWORD to your name and
* password for the DB
*/
function Setup ($user, $pass, $host, $db) {
$this->user = $user;
$this->pass = $pass;
$this->host = $host;
$this->db = $db;
}
function Create ($db) {
if (!$this->user) {
# Set this to your default username
$this->user = "generator";
}
if (!$this->pass) {
# Set this to your default password
$this->pass = "maakh3tnu";
}
if (!$this->host) {
# Set this to your default database host
$this->host = "localhost";
}
if (!$this->db && !$db) {
# Set this to your default database
$this->db = "generator";
} else {
$this->db = $db;
}
$this->id = @mysql_connect($this->host, $this->user, $this->pass) or
MySQL_ErrorMsg("Unable to connect to MySQL server: $this->host : '$SERVER_NAME'");
$this->selectdb($this->db);
}
function SelectDB ($db) {
@mysql_select_db($db, $this->id) or
MySQL_ErrorMsg ("Unable to select database: $db");
}
# Use this function is the query will return multiple rows. Use the Fetch
# routine to loop through those rows.
function Query ($query) {
$this->result = @mysql_query($query, $this->id) or
MySQL_ErrorMsg ("Unable to perform query: $query");
$this->rows = @mysql_num_rows($this->result);
// echo "query:<br>$query<br>";
$this->a_rows = @mysql_affected_rows($this->id);
}
function QueryTry ($query) {
$res='';
$this->rows = 0;
$this->result = @mysql_query($query, $this->id) or
$res=mysql_error();
if ($res=='') {
$this->rows = @mysql_num_rows($this->result);
// echo "query:<br>$query<br>";
$this->a_rows = @mysql_affected_rows($this->id);
}
return($res);
}
# Use this function if the query will only return a
# single data element.
function QueryItem ($query) {
$this->result = @mysql_query($query, $this->id) or
MySQL_ErrorMsg ("Unable to perform query: $query");
// echo "query:<br>$query<br>";
$this->rows = @mysql_num_rows($this->result);
$this->a_rows = @mysql_affected_rows($this->id);
$this->data = @mysql_fetch_array($this->result);
// MySQL_ErrorMsg ("Unable to fetch data from query: $query");
// MySQL_ErrorMsg ("Geen gegevens!: $query");
return($this->data[0]);
}
# This function is useful if the query will only return a
# single row.
function QueryRow ($query) {
$this->result = @mysql_query($query, $this->id) or
MySQL_ErrorMsg ("Unable to perform query: $query");
$this->rows = @mysql_num_rows($this->result);
$this->a_rows = @mysql_affected_rows($this->id);
$this->data = @mysql_fetch_array($this->result) or
MySQL_ErrorMsg ("Unable to fetch data from query: $query");
return($this->data);
}
function Fetch ($row) {
@mysql_data_seek($this->result, $row) or
MySQL_ErrorMsg ("Unable to seek data row: $row");
$this->data = @mysql_fetch_array($this->result) or
MySQL_ErrorMsg ("Unable to fetch row: $row");
}
function Insert ($query) {
$this->result = @mysql_query($query, $this->id) or
MySQL_ErrorMsg ("Unable to perform insert: $query");
$this->a_rows = @mysql_affected_rows($this->id);
}
function InsertID () {
return mysql_insert_id();
}
function Update ($query) {
$this->result = @mysql_query($query, $this->id) or
MySQL_ErrorMsg ("Unable to perform update: $query");
// echo "query:<br>$query<br>";
$this->a_rows = @mysql_affected_rows($this->id);
}
function Delete ($query) {
$this->result = @mysql_query($query, $this->id) or
MySQL_ErrorMsg ("Unable to perform Delete: $query");
// echo "query:<br>$query<br>";
$this->a_rows = @mysql_affected_rows($this->id);
}
}
/* ********************************************************************
* MySQL_ErrorMsg
*
* Print out an MySQL error message
*
*/
function MySQL_ErrorMsg ($msg) {
# Close out a bunch of HTML constructs which might prevent
# the HTML page from displaying the error text.
echo("</ul></dl></ol>\n");
echo("</table></script>\n");
// echo"<script>alert('Fout bij gegevensverwerking!')</script>";
# Display the error message
$text = "<font color=\"#ff0000\" size=+2><p>Error: $msg :";
$text .= mysql_error();
$text .= "</font>\n";
die($text);
}
function quote ($value)
{
if (get_magic_quotes_gpc()) {
$value = stripslashes($value);
}
// if (!is_numeric($value)) {
// mysql_real_escape_string
$value = "'" . addslashes($value) . "'";
// }
return $value;
}
?>
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.