load('database_config.xml'); $server = $doc->getElementsByTagName("server")->item(0)->nodeValue; $user = $doc->getElementsByTagName("user")->item(0)->nodeValue; $password = $doc->getElementsByTagName("password")->item(0)->nodeValue; $database = $doc->getElementsByTagName("database")->item(0)->nodeValue; if ($server == NULL || $user == NULL || $password == NULL || $database == NULL) { error_log ("SERVER, USER, PASSWORD OR DATABASE IS NULL\n"); } else { $ConnInfo = new ConnectionInfo(); $ConnInfo->server = $server; $ConnInfo->user = $user; $ConnInfo->password = $password; $ConnInfo->database = $database; } return $ConnInfo; } /** * This method establishes a connection to the database. * @return dbhandle, upon successfull execution a non null * handle to the database connection is returned. Else it * will be null. */ function ConnectToDatabase() { $connInfo = GetConnectionInfo(); if ($connInfo != NULL) { $dbhandle = mssql_connect($connInfo->server, $connInfo->user, $connInfo->password) or die ("Couldn't connect to the server!!!"); $selected = mssql_select_db($connInfo->database, $dbhandle) or die ("Couldn't open the database!!!"); } return $dbhandle; } /** * This method executes a query that it receives. * @param query the query to execute * @return non-NULL upon success and NULL otherwise. */ function ExecuteQuery($query) { return mssql_query($query); } /** * This method close the connection that is established to the * database. * @param dbhandle handle to the database */ function CloseDatabase($dbhandle) { mssql_close($dbhandle); } /** * This method returns the a value from a mssql 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. */ function GetMSSQLValue($result, $raw, $column) { return mssql_result($result, $raw, $column); } ?>