How to: Load My Configuration Data

What is the best way to load your web application configuration? All web applications today have at least a single configuration file or multiple ones. What is the best way to load your configuration file? from database, from an XML file, from INI file or from SESSIONS??? To find out which method is the best I decided to run a few tests for each method and to see the time that a method required to be executed and how much memory it needed.

My conclusions where that as many times as I run the tests saving configuration data in sessions is the fastest way with a slightly difference in memory usage which increases a bit compares to loading from the INI file. Loading the configuration settings of your application in sessions or INI file saves resources and improves performance. I thing that a good practice is to have configuration in INI file and when ever the file updates to load the configuration for each visitor in its sessions instead of reading from INI. But at what cost?

Below you can see the results generated on the fly.

Write & Read UTF-8 from Mysql

The following php script shows how we can write and read Greek characters in a mysql database. Before starting check the encoding of your file. If you are using Zend studio go to Edit->Set Encoding and select Other: utf-8. Now in your php script after establishing a connection to the database type the following queries in order to set the names and characters equal to utf-8 for the specified connection, for me is just one connection so I do not use the resource as a parameter.

mysql_query(“SET NAMES ‘utf8′”);
mysql_query(“SET CHARACTER SET ‘utf8′”);

Next you can type you insert query:

$query = sprintf(‘INSERT INTO test (text) VALUES (“%s”)’, ‘write greek text here’);

And finally you can start reading from your database:

$q = mysql_query(“select text from test order by text”");
$row = mysql_fetch_object($q);

echo $row->text;
$row = mysql_fetch_object($q);

This small piece of information can save you a lot of time when trying to handle utf-8 characters. Good luck.

PN Generator (Pagination)

This class can be used to generate links to browse MySQL database query results split in multiple pages.

It takes as parameters an SQL query and a limit number of results to display per page.

The class executes the query to obtain the total number of results and generates HTML links to browse to the next, previous and other pages over which the query results will be displayed.

Inside the zip file there is a file called example1.php which you need to configure first by setting up your database connection strings, your query and how many results to display in each page.

  • You can download the class file here.

PHP: debugTool

DebugTool v1.0 is a new project that will help php developers to use it on the fly to check if their website is working right. Using this tool it will save them time from trying to figure out why something is not working, are my variables set, clean session and request variables on the fly without closing your browser every time.

Snapshot of debugTool:

Snapshot of debugTool with comments:

  • A Demo for this project can be found here.
  • Download project debugTool v1.0 here.