-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclass.database.php
More file actions
69 lines (61 loc) · 1.66 KB
/
class.database.php
File metadata and controls
69 lines (61 loc) · 1.66 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
<?php
/**
* <b>Database Connection</b> class.
* @author Php Object Generator
* @version 3.0e / PHP4
* @see http://www.phpobjectgenerator.com/
* @copyright Free for personal & commercial use. (Offered under the BSD license)
*/
Class Database
{
var $connection;
function Database()
{
$databaseName = $GLOBALS['configuration']['db'];
$serverName = $GLOBALS['configuration']['host'];
$databaseUser = $GLOBALS['configuration']['user'];
$databasePassword = $GLOBALS['configuration']['pass'];
$databasePort = $GLOBALS['configuration']['port'];
$this->connection = mysql_connect ($serverName.":".$databasePort, $databaseUser, $databasePassword) or die('I cannot connect to the database. Please edit configuration.php with your database configuration.');
mysql_select_db ($databaseName) or die ('I cannot find the specified database "'.$databaseName.'". Please edit configuration.php.');
}
function Connect()
{
static $database = null;
if (!isset($database))
{
$database = new Database();
}
return $database->connection;
}
function Reader($query, $connection)
{
$cursor = mysql_query($query, $connection);
return $cursor;
}
function Read($cursor)
{
return mysql_fetch_assoc($cursor);
}
function NonQuery($query, $connection)
{
mysql_query($query, $connection);
$result = mysql_affected_rows($connection);
if ($result == -1)
{
return false;
}
return $result;
}
function Query($query, $connection)
{
$result = mysql_query($query, $connection);
return mysql_num_rows($result);
}
function InsertOrUpdate($query, $connection)
{
$result = mysql_query($query, $connection);
return intval(mysql_insert_id($connection));
}
}
?>