summaryrefslogtreecommitdiff
path: root/backend/php/src/objects/class.database.php
authorGiulio Cesare Solaroli <giulio.cesare@clipperz.com>2011-10-02 23:56:18 (UTC)
committer Giulio Cesare Solaroli <giulio.cesare@clipperz.com>2011-10-02 23:56:18 (UTC)
commitef68436ac04da078ffdcacd7e1f785473a303d45 (patch) (side-by-side diff)
treec403752d66a2c4775f00affd4fa8431b29c5b68c /backend/php/src/objects/class.database.php
parent597ecfbc0249d83e1b856cbd558340c01237a360 (diff)
downloadclipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.zip
clipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.tar.gz
clipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.tar.bz2
First version of the newly 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.php79
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 @@
+<?php
+/**
+* <b>Database Connection</b> class.
+* @author Php Object Generator
+* @version 3.0d / PHP5.1
+* @see http://www.phpobjectgenerator.com/
+* @copyright Free for personal & commercial use. (Offered under the BSD license)
+*/
+ Class Database
+{
+ public $connection;
+
+ private 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);
+ if ($this->connection)
+ {
+ if (!mysql_select_db ($databaseName))
+ {
+ throw new Exception('I cannot find the specified database "'.$databaseName.'". Please edit configuration.php.');
+ }
+ }
+ else
+ {
+ throw new Exception('I cannot connect to the database. Please edit configuration.php with your database configuration.');
+ }
+ }
+
+ public static function Connect()
+ {
+ static $database = null;
+ if (!isset($database))
+ {
+ $database = new Database();
+ }
+ return $database->connection;
+ }
+
+ public static function Reader($query, $connection)
+ {
+ $cursor = mysql_query($query, $connection);
+ return $cursor;
+ }
+
+ public static function Read($cursor)
+ {
+ return mysql_fetch_assoc($cursor);
+ }
+
+ public static function NonQuery($query, $connection)
+ {
+ mysql_query($query, $connection);
+ $result = mysql_affected_rows($connection);
+ if ($result == -1)
+ {
+ return false;
+ }
+ return $result;
+
+ }
+
+ public static function Query($query, $connection)
+ {
+ $result = mysql_query($query, $connection);
+ return mysql_num_rows($result);
+ }
+
+ public static function InsertOrUpdate($query, $connection)
+ {
+ $result = mysql_query($query, $connection);
+ return intval(mysql_insert_id($connection));
+ }
+}
+?>