Archive for February, 2007

function getDBConnection() { global $dbHostName, $dbUserName, $dbPassword, $dbName;

Thursday, February 1st, 2007

function getDBConnection() { global $dbHostName, $dbUserName, $dbPassword, $dbName; // Get a persistent database connection if (!($link = mysql_pconnect($dbHostName, $dbUserName, $dbPassword))) { return new Function_Result( “Internal Error: Could not open database connection”, null); } // select mysql database if (!mysql_select_db($dbName, $link)) { return new Function_Result( “Internal Error: Could not selectdatabase “, null); } return new Function_Result(null, $link); } The functions open(), close(), read(), write(), destroy(), and gc() are the session handler functions which store the session data in the back-end database. One of the important requirements for the application was to store the session data in a MySQL table, so that it can be used by the instances of PHP running on different servers. The function open() is called for initializing the session storage. The function doesn’t do anything because the database table session is already created: function open($save_path, $session_name) { return true; } The function close() is the close handler of session storage. The function too doesn’t do anything: function close() { return true; } The function read() returns the session data of session with $id as its session identifier: function read($id) { global $dbHostName, $dbUserName, $dbPassword, $dbName; Open a persistent database connection: Page 557

Hint: This post is supported by Gama web hosting php services

function convertDateToMysqlFormat($dateStr) { list ($month, $day, $year) =

Thursday, February 1st, 2007

function convertDateToMysqlFormat($dateStr) { list ($month, $day, $year) = split(”/”, $dateStr); return $year . “-” . $month . “-” . $day; } The function checkSessionAuthenticated() checks if the user session is authenticated. If the user session is not authenticated then the function sends a WML error page: function checkSessionAuthenticated() { global $isAuthenticated; Start the session: session_start(); Return true if the $isAuthenticated variable is stored in the session and its value is true. Else return an error page: if (session_is_registered(”isAuthenticated”) && $isAuthenticated) { return true; } else { sendErrorPage(”Unauthenticated Session”); exit; } } The class Function_Result encapsulates the return value of most of the functions. The member variable $errorMessage stores the error message, and the member variable $returnValue stores the return value. On failure the value of member variable $returnValue is null: class Function_Result { var $errorMessage; var $returnValue; The constructor of Function_Result sets the value of member variables $errorMessageand $returnValue: function Function_Result($errMessage, $retValue) { $this->errorMessage = $errMessage; $this->returnValue = $retValue; } } The function getDBConnection() returns the MySQL database connection: Page 556

Hint: If you are looking for high quality and reliable webspace provider to host and run your jsp hosting application check Sandzak jsp web hosting provider

printf(”n”); } Most of the mobile devices do

Thursday, February 1st, 2007

printf(”n”); } Most of the mobile devices do not support cookies, so we will have to use the session information in the URL itself. The function getSessionIdString() returns the session id string that will have to be appended to all the anchor elements generated by the PHP script: // Get the sessionId string function getSessionIdString() { return session_name().”=”.session_id(); } The function generateOptionElement() generates WML option element: // Generate option element function generateOptionElement($href, $displayText) { printf(”n”); } The function getDateString() returns the current date in the format YYYY-MM-DD, where YYYY corresponds to the year, MM to the month, and DD to the day component of the date. This function is used when inserting date columns into MySQL tables: // Returns Date function getDateString() { return date(Y-m-d); } The function convertDateFromMysqlFormat() coverts the date from YYYY-MM-DD format to MM/DD/YYYYformat. The argument $dateStr contains date in YYYY-MM-DD format: function convertDateFromMysqlFormat($dateStr) { list ($year, $month, $day) = split(”-”, $dateStr); return $month . “/” . $day . “/” . $year; } The function convertDateToMysqlFormat() converts the date from MM/DD/YYYY format to YYYY MM-DDformat: Page 555
Note: If you are looking for cheapest and affordable webspace to host and run your servlet application check Astra j2ee hosting services