-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabase.php
More file actions
61 lines (51 loc) · 1.47 KB
/
Database.php
File metadata and controls
61 lines (51 loc) · 1.47 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
<?php
include_once 'etc/config.php';
# DB connection function.
function connectDB()
{
global $DB, $Host, $User, $Passwd;
$connection = mysql_connect($Host, $User, $Passwd);
if (!isset($connection))
punt("Can't connect to MySQL server $Host");
if (!mysql_select_db($DB))
punt("Can't connect to MySQL database $DB on $Host");
}
#This function is used for submitting queries to the database
function queryDB($query)
{
$result = mysql_query($query . ";");
if (!$result) {
punt('Error in submitting the query in the queryDB() fucntion', $query);
}
return ($result);
}
#This function is used for submitting updates to the database
function updateDB($updateSql)
{
$result = mysql_query($updateSql . ";");
if (!$result) {
punt('Error in submitting the update to the database in the updateDB fucntion', $updateSql);
return (false);
}
return (true);
}
#This fucntion takes in a query result object
#This fucntion returns the next row in associative array format
function nextRow($result)
{
if (!$result) {
punt('Bad result object passed into the nextRow() fucntion');
}
return (mysql_fetch_array($result));
}
#This fucntion takes in a query result object
#This fucntion returns the number of rows from a query
function numRows($result)
{
if (!$result) {
punt('Unable to find the number of rows in the numRows() fucntion');
}
return (mysql_num_rows($result));
}
connectDB();
?>