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 = sqlsrv_connect( $this->connectionInfo->server, array( "Database" => $this->connectionInfo->database, "UID" => $this->connectionInfo->user, "PWD" => $this->connectionInfo->password, "MultipleActiveResultSets" => 0 ) ) or die ("Couldn't connect to the server!!!"); } return true; } /** * This method close the connection that is established to the * database. */ public function CloseDatabase() { sqlsrv_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 sqlsrv_query( $this->dbhandle, $query ); } /** * 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 sqlsrv_fetch_array($result); } /** * 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 { $dbval = $this->GetSQLValue($result); return $dbval[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"); } } ?>