“Lost connection to MySQL server during query”

If you don’t perform any query after creating connection to MySQL server, it may cause this problem.

The simple solution is to use mysql_ping PHP function to check the connection, if it’s lost, attempt to recreate it.

if (!mysql_ping($linkId)) {
    mysql_close($linkId);
    mysql_connect('host', 'username', 'password');
    mysql_select_db('db_name');
    // do your normal queries here
}

Displaying Data From Arrays in Sortable Grids

Sometimes, you want to automatically render data from arrays, database queries… in the grids but feeling lazy to manually write HTML line by line. I’ve written a class named ‘Fete_ViewControl_DataGrid’ which can help you do that. This class also supports sorting, it can be easily integrated with other frameworks or your existing codes.

The class and examples have been uploaded to PHPClasses.org at http://www.phpclasses.org/browse/package/5476.html. I will update every further change on that repository.

I’ve received some emails that suggest paging feature. I’ll be trying to find a proper solution. Thank you all for your feedbacks :)

How To Create Multiple Themes Application With Zend Framework?

Zend Framework is a good choice for developers who want a well-designed, flexible PHP framework.

I’ve been using PHP because of its speed and flexibility, which are weaknesses of other scripting languages.

With phpBB, WordPress… or almost other PHP softwares, the users can have various themes to switch between them easily. Zend Framework does not natively support this feature but we can do it using 2 solutions.

WordPress GStyle Theme

I like Google’s services because they are simple and easy to use. I like WordPress, too. So I’ve made this theme to combine them for private use and named it GStyle :D

PHP: How To Highlight Search Without Affecting HTML Tags

This class enables you to highlight keywords in the search results without affecting HTML tags. It can exactly highlight the string in double quotes of the keyword. For example:

$highlightedString = Fete_Util_Text_Highlighter::createInstance('<b>', '</b>')
->highlight('PHP rules the world', '"PHP rules" world'); // prints <b>PHP rules</b> the <b>world</b>