This repository has been archived by the owner on Mar 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnectTest.php
63 lines (49 loc) · 1.56 KB
/
connectTest.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
<?PHP
CLASS DB_Class {
VAR $db;
///////////////////////////
FUNCTION DB_Class($dbname, $username, $password) {
$this->db = MYSQL_CONNECT ('localhost', $username, $password)
or DIE ("Unable to connect to Database Server");
MYSQL_SELECT_DB ($dbname, $this->db) or DIE ("Could not select database");
}
FUNCTION query($sql) {
$result = MYSQL_QUERY ($sql, $this->db) or DIE ("Invalid query: " . MYSQL_ERROR());
RETURN $result;
}
///////////////////////////
FUNCTION fetch($sql) {
$data = ARRAY();
$result = $this->query($sql);
WHILE($row = MYSQL_FETCH_ASSOC($result)) {
$data[] = $row;
}
RETURN $data;
}
///////////////////////////
FUNCTION getone($sql) {
$result = $this->query($sql);
IF(MYSQL_NUM_ROWS($result) == 0)
$value = FALSE;
ELSE
$value = MYSQL_RESULT($result, 0);
RETURN $value;
}
///////////////////////////
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<?PHP
// usage example....
$dbconnect = NEW DB_Class('table', 'user', 'password');
$query = "SELECT user_id FROM user_table WHERE $match = $search ORDER BY user_id DESC";
$result = $dbconnect->fetch($query);
?>
<body>
</body>
</html>