connectionInfo = $connInfo; } /** * This method establishes a connection to the database. * @return boolean, upon successfull execution true is returned. * Otherwise false will be returned. */ public function ConnectToDatabase() { if ($this->connectionInfo != NULL) { $this->dbhandle = mysql_connect($this->connectionInfo->server, $this->connectionInfo->user, $this->connectionInfo->password) or die ("Couldn't connect to the server!!!"); $selected = mysql_select_db($this->connectionInfo->database, $this->dbhandle) or die ("Couldn't open the database!!!"); } return true; } /** * This method close the connection that is established to the * database. */ public function CloseDatabase() { mysql_close($this->dbhandle); } /** * This method executes a query that it receives. * @param query the query to execute * @return non-NULL upon success and NULL otherwise. */ public function ExecuteQuery($query) { return mysql_query($query, $this->dbhandle); } /** * This method returns the a value from a sql result set (a tuple * returned after execution of ExecuteQuery method. * @param result, the result obtained from ExecuteQuery method. * @return the value at (raw, column) of the tuple. */ public function GetSQLValue($result) { return mysql_fetch_array($result, MYSQL_BOTH); } /** * Gets the ID of the last inserted record. returns -1 if error. */ public function GetInsertID() { $insertID = mysql_insert_id($this->dbhandle); if($insertID == NULL) { return -1; } else { return $insertID; } } /** * Begin a transaction. return status will be not null if success */ public function BeginTransaction() { return $this->ExecuteQuery("START TRANSACTION"); } /** * Commit a transaction. return status will be not null if success */ public function CommitTransaction() { return $this->ExecuteQuery("COMMIT"); } /** * Rollback a transaction. return status will be not null if success */ public function RollbackTransaction() { return $this->ExecuteQuery("ROLLBACK"); } } ?>