author | Giulio Cesare Solaroli <giulio.cesare@solaroli.it> | 2011-10-03 16:04:12 (UTC) |
---|---|---|
committer | Giulio Cesare Solaroli <giulio.cesare@solaroli.it> | 2011-10-03 16:04:12 (UTC) |
commit | 541bb378ddece2eab135a8066a16994e94436dea (patch) (unidiff) | |
tree | ff160ea3e26f7fe07fcfd401387c5a0232ca715e /backend/php/src/objects/class.database.php | |
parent | 1bf431fd3d45cbdf4afa3e12afefe5d24f4d3bc7 (diff) | |
parent | ecad5e895831337216544e81f1a467e0c68c4a6a (diff) | |
download | clipperz-541bb378ddece2eab135a8066a16994e94436dea.zip clipperz-541bb378ddece2eab135a8066a16994e94436dea.tar.gz clipperz-541bb378ddece2eab135a8066a16994e94436dea.tar.bz2 |
Merge pull request #1 from gcsolaroli/master
First version of the restructured repository
Diffstat (limited to 'backend/php/src/objects/class.database.php') (more/less context) (ignore whitespace changes)
-rw-r--r-- | backend/php/src/objects/class.database.php | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/backend/php/src/objects/class.database.php b/backend/php/src/objects/class.database.php new file mode 100644 index 0000000..e8a13f7 --- a/dev/null +++ b/backend/php/src/objects/class.database.php | |||
@@ -0,0 +1,79 @@ | |||
1 | <?php | ||
2 | /** | ||
3 | * <b>Database Connection</b> class. | ||
4 | * @author Php Object Generator | ||
5 | * @version 3.0d / PHP5.1 | ||
6 | * @see http://www.phpobjectgenerator.com/ | ||
7 | * @copyright Free for personal & commercial use. (Offered under the BSD license) | ||
8 | */ | ||
9 | Class Database | ||
10 | { | ||
11 | public $connection; | ||
12 | |||
13 | private function Database() | ||
14 | { | ||
15 | $databaseName = $GLOBALS['configuration']['db']; | ||
16 | $serverName = $GLOBALS['configuration']['host']; | ||
17 | $databaseUser = $GLOBALS['configuration']['user']; | ||
18 | $databasePassword = $GLOBALS['configuration']['pass']; | ||
19 | $databasePort = $GLOBALS['configuration']['port']; | ||
20 | $this->connection = mysql_connect ($serverName.":".$databasePort, $databaseUser, $databasePassword); | ||
21 | if ($this->connection) | ||
22 | { | ||
23 | if (!mysql_select_db ($databaseName)) | ||
24 | { | ||
25 | throw new Exception('I cannot find the specified database "'.$databaseName.'". Please edit configuration.php.'); | ||
26 | } | ||
27 | } | ||
28 | else | ||
29 | { | ||
30 | throw new Exception('I cannot connect to the database. Please edit configuration.php with your database configuration.'); | ||
31 | } | ||
32 | } | ||
33 | |||
34 | public static function Connect() | ||
35 | { | ||
36 | static $database = null; | ||
37 | if (!isset($database)) | ||
38 | { | ||
39 | $database = new Database(); | ||
40 | } | ||
41 | return $database->connection; | ||
42 | } | ||
43 | |||
44 | public static function Reader($query, $connection) | ||
45 | { | ||
46 | $cursor = mysql_query($query, $connection); | ||
47 | return $cursor; | ||
48 | } | ||
49 | |||
50 | public static function Read($cursor) | ||
51 | { | ||
52 | return mysql_fetch_assoc($cursor); | ||
53 | } | ||
54 | |||
55 | public static function NonQuery($query, $connection) | ||
56 | { | ||
57 | mysql_query($query, $connection); | ||
58 | $result = mysql_affected_rows($connection); | ||
59 | if ($result == -1) | ||
60 | { | ||
61 | return false; | ||
62 | } | ||
63 | return $result; | ||
64 | |||
65 | } | ||
66 | |||
67 | public static function Query($query, $connection) | ||
68 | { | ||
69 | $result = mysql_query($query, $connection); | ||
70 | return mysql_num_rows($result); | ||
71 | } | ||
72 | |||
73 | public static function InsertOrUpdate($query, $connection) | ||
74 | { | ||
75 | $result = mysql_query($query, $connection); | ||
76 | return intval(mysql_insert_id($connection)); | ||
77 | } | ||
78 | } | ||
79 | ?> | ||