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 = mssql_connect($this->connectionInfo->server, $this->connectionInfo->user, $this->connectionInfo->password) or die ("Couldn't connect to the server!!!"); $selected = mssql_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() { mssql_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 mssql_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. * @param raw, the raw number * @param column, the column number * @return the value at (raw, column) of the tuple. */ public function GetSQLValue($result, $raw, $column) { return mssql_result($result, $raw, $column); } /** * Gets the ID of the last inserted record. returns -1 if error. */ public function GetInsertID() { $result = $this->ExecuteQuery("SELECT @@identity"); if(!$result) { return -1; } else { return $this->GetSQLValue($result, 0, 0); } } /** * Begin a transaction. return status will be not null if success */ public function BeginTransaction() { return $this->ExecuteQuery("BEGIN TRAN"); } /** * Commit a transaction. return status will be not null if success */ public function CommitTransaction() { return $this->ExecuteQuery("COMMIT TRAN"); } /** * Rollback a transaction. return status will be not null if success */ public function RollbackTransaction() { return $this->ExecuteQuery("COMMIT TRAN"); } } ?>