Archive for July, 2007

Web site templates - Part II: Developing Intranet Solutions Listing 4-2 (Continued)

Friday, July 27th, 2007

Part II: Developing Intranet Solutions Listing 4-2 (Continued) $this->caller_class = (!empty($params[ caller ])) ? $params[ caller ] : null; $this->error_message = array(); //error_reporting(E_ERROR | E_WARNING | E_NOTICE); $this->load_error_code(); } function alert($code = null, $flag = null) { $msg = $this->get_error_message($code); if (!strlen($msg)) { $msg = $code; } if ($flag == null) { echo ; } else if (!strcmp($flag, close )){ echo ; } else { echo ; } } function get_error_message($code = null) { if (isset($code)) { if (is_array($code)) { $out = array(); foreach ($code as $entry) { array_push($out, $this->error_message[$entry]); } return $out; } else { return (! empty($this->error_message[$code])) ? $this>error_message[$code] : null; } } else { return (! empty($this->error_message[ MISSING ])) ? $this>error_message[ MISSING ] : null; }

Web site layout - Chapter 4: Architecture of an Intranet Application .

Thursday, July 26th, 2007

Chapter 4: Architecture of an Intranet Application . apiVersion(): This is a utility method that returns the version number of the DBI object. The DBI abstraction class enables you to connect to any database and perform any SQL query, such as SELECT, INSERT, UPDATE, DELETE, and so forth. Because it hides the database vendor-specific details from your application, porting to other databases become a much easier task. Now let s look at how we can develop an error handler class. Creating an Error Handler Class Every application needs to display error messages. In the old days, error messages were usually hard-coded in the executable programs and were very difficult to understand, let alone modify! Now, in the days of Web interface, we should not resort to the old way of showing hard-coded error messaging because the application can be used in so many parts of the world. Error messages written in English are just not friendly enough for the world in this Internet age. So applications that have internationalizable error message support will have broader reach. Listing 4-2 shows an error message handler, which loads and displays error messages in the application s default language. Because an application s default language can be changed in the configuration file, it becomes very easy to display error messages in different languages. Listing 4-2: class.ErrorHandler.php * @access public */ define( ERROR_HANDLER_LOADED , TRUE); class ErrorHandler { function ErrorHandler($params = null) { global $DEFAULT_LANGUAGE; $this->language = $DEFAULT_LANGUAGE; Continued

Part II: Developing Intranet Solutions // Insert the (Web hosting domain names)

Thursday, July 26th, 2007

Part II: Developing Intranet Solutions // Insert the path in the PHP include_path so that PHP // looks for our PEAR, PHPLIB and application framework // classes in these directories ini_set( include_path , : . $PATH . : . ini_get( include_path )); // Now load the DB.php class from PEAR require_once DB.php ; // Now load our DBI class from application framework require_once( class.DBI.php ); // Setup the database URL $DB_URL = mysql://root:foobar@localhost/foobar ; // Create a DBI object that connects to the // database URL $dbi = new DBI($DB_URL); if (! $dbi->isConnected()) { echo Connection failed for $DB_URL
; exit; } $id = 100; $name = Joe Gunchy ; $name = $dbi->quote($name); $statement = INSERT INTO PROD_TBL (ID,NAME) . VALUES($id, $name) ; $result = $dbi->query($statement); if ($result == NULL) { echo Database error: . $dbi->getError() .
n ; } else { echo Added $name in database.
n ; } ?>

Web hosting india - Chapter 4: Architecture of an Intranet Application The

Thursday, July 26th, 2007

Chapter 4: Architecture of an Intranet Application The SQL statement SELECT ID, NAME FROM PROD_TBL is stored in $statement variable and passed to the DBI::query() method. The result is tested first for null. If the result is null, the database error is printed using the DBI::getError() method. If there are no database errors, the next check is made to see if there are any rows using the numRow() method from the $result object. If there are no rows, an appropriate message is printed. If there are data in the returned $result object, the result is printed in a loop using the fetchRow() method. The row data is fetched in $row object. The $row->DATA_FIELD method is used to get the data for each field. For example, to retrieve the NAME field data, the $row->NAME value is accessed. . quote(): This is a utility function that puts a pair of single quotes around a string to protect the string from being passed without quotation. Here s an example in which the $name field is single-quoted using $this->dbi>quote($name) call:

Part II: Developing Intranet Solutions // Setup the (How to cite a web site)

Wednesday, July 25th, 2007

Part II: Developing Intranet Solutions // Setup the database URL $DB_URL = mysql://root:foobar@localhost/products ; // Create a DBI object that connects to the // database URL $dbi = new DBI($DB_URL); if (! $dbi->isConnected()) { echo Connection failed for $DB_URL
; exit; } // Create a SQL statement to fetch data $statement = SELECT ID, NAME FROM PROD_TBL ; // Execute the statement using DBI query method $result = $dbi->query($statement); // If the result of query is NULL then show // database error message if ($result == NULL) { echo Database error: . $dbi->getError() . n ; // Else check if there are no data available or not } else if (! $result->numRows()){ echo No rows found. ; // Now data is available so fetch and print data } else { echo

IDtNAME ;   while ($row = $result->fetchRow()) {   echo $row->ID,  t , $row->NAME,   ;  }  echo  

; } ?>

Chapter 4: (Mac os x web server) Architecture of an Intranet Application If

Wednesday, July 25th, 2007

Chapter 4: Architecture of an Intranet Application If the query is successful, it returns the result object. The result object can be used to fetch rows. For example, the test_query.php script tries to fetch data from a table called PROD_TBL using a database URL such as mysql://root:foobar@localhost/products.

Part II: (Freelance web design) Developing Intranet Solutions // Dump the

Tuesday, July 24th, 2007

Part II: Developing Intranet Solutions // Dump the contents of the DBI object to // see what it contains. echo

 ; print_r($dbi); echo  

; ?> Here, $dbi is an instance of the DBI object created from class.DBI.php. The constructor method has to be passed a database URL which has the following syntax: database_type://username:password.tabase_host/database_name The $DB_URL variable was set to create a database URL that pointed to a MySQL database (mysql) named mydb on host called localhost The database can be accessed using the root user account and foobar password. The DBI() method sets the DB URL passed to itself as db_url member variable and calls the connect() method to connect to the given database. The constructor sets the fetch mode to DB_FETCHMODE_OBJECT, which allows us to fetch database rows as objects. . connect(): By default, the DBI() constructor method calls the connect() function directly to establish the connection, so you don t need to. connect() connects to the database specified in db_url member variable of the object. It sets a member variable dbh to the database handle object created by the DB::connect() method, which is found in the PEAR DB package. connect also sets a member variable called connected to Boolean TRUE or FALSE and returns that value. . disconnect(): The disconnect() function disconnects the DBI object from the database. The terminate() function in PHPApplication class (class. PHPApplication.php) calls the disconnect() function if the application is connected to a database. See terminate() function in PHPApplicationclass for details. . query(): This function performs a SQL query on the connected database. The result of the query is stored in a result object called $result. If the query returns SQL error(s), a member variable called $this->dbi->error is set to the error message and null is returned.

Chapter 4: (Kids web site) Architecture of an Intranet Application //

Tuesday, July 24th, 2007

Chapter 4: Architecture of an Intranet Application // setting below. $PEAR_DIR = $_SERVER[ DOCUMENT_ROOT ] . /pear ; // If you have installed PHPLIB in a different // directory than %DocumentRoot%/phplib, change // the setting below. $PHPLIB_DIR = $_SERVER[ DOCUMENT_ROOT ] . /phplib ; // If you have installed framework directory in // a different directory than // %DocumentRoot%/framework, change the setting below. $APP_FRAMEWORK_DIR=$_SERVER[ DOCUMENT_ROOT ] . /framework ; // Create a path consisting of the PEAR, // PHPLIB and our application framework // path ($APP_FRAMEWORK_DIR) $PATH = $PEAR_DIR . : . $PHPLIB_DIR . : . $APP_FRAMEWORK_DIR; // Insert the path in the PHP include_path so that PHP // looks for our PEAR, PHPLIB and application framework // classes in these directories ini_set( include_path , : . $PATH . : . ini_get( include_path )); // Now load the DB.php class from PEAR require_once DB.php ; // Now load our DBI class from application framework // directory require_once( class.DBI.php ); // Set the database URL to point to a MySQL // database. In this example, the database is // pointing to a MySQL database called auth on // the localhost server, which requires username // (root) and password (foobar) to login $DB_URL = mysql://root:foobar@localhost/auth ; // Create a DBI object using our DBI class // Use the database URL to initialize the object // and make connection to the database $dbi = new DBI($DB_URL);

Unlimited web hosting - Part II: Developing Intranet Solutions Listing 4-1 (Continued)

Monday, July 23rd, 2007

Part II: Developing Intranet Solutions Listing 4-1 (Continued) $this->error_type = $TABLE_UNKNOWN_ERROR; } } function isError() { return (!empty($this->error)) ? 1 : 0; } function isErrorType($type = null) { return ($this->error_type == $type) ? 1 : 0; } function getError() { return $this->error; } function quote($str) { return . $str . ; } function apiVersion() { return $VERSION; } } ?> Here are the functions the DBI class implements: . DBI(): This is the constructor method, which creates the instances of the DBI object. For example, here is a script called test_dbi.php that creates a DBI object.

Web server type - Chapter 4: Architecture of an Intranet Application {

Monday, July 23rd, 2007

Chapter 4: Architecture of an Intranet Application { return $this->connected; } function disconnect() { if (isset($this->dbh)) { $this->dbh->disconnect(); return 1; } else { return 0; } } function query($statement) { $result = $this->dbh->query($statement); if (DB::isError($result)) { $this->setError($result->getMessage()); return null; } else { return $result; } } function setError($msg = null) { global $TABLE_DOES_NOT_EXIST, $TABLE_UNKNOWN_ERROR; $this->error = $msg; if (strpos($msg, no such table )) { $this->error_type = $TABLE_DOES_NOT_EXIST; } else { Continued