Choose your database:
MS SQL Server
SQL Anywhere

Subscribe to our news:
Neil McPherson: "Thanks very much for your advice. I would just like to add that SQL Maestro makes life so much easier to work with Firebird, I have tried some of the other management tools but Maestro is such a nicely organized product and it has never let me down".
Kelly Dires: "First let me say we are very impressed with Firebird Data Wizard, it was not only the fastest but also the easiest to use out of the six tools of this class tested".


Add your opinion

SQL Maestro Group / Products / Firebird / Resources / Using a third-party library in the script created by PHP Generator

How to use a third-party library in the script created by PHP Generator?

Last modified: Sep 22, 2010

Prev Next


The article presents a step-by-step explanation of a third-party library use in the script created by PHP Generator. As an example we take a case when there is a need to implement a syntax highlighting using the Geshi engine.


Creating web applications we are trying to make each page comfortable for visitors. Such comfort requires a lot of hard work from web developers, but fortunately in most cases the complex functionality has already been developed and incorporated into ready-to-use libraries, so it is not necessary to implement the same features once again. The good news is PHP Generator gives you a great opportunity to activate third-party components easily.

The final target of this tutorial is to get a webpage with the list of code fragments highlighted according to the programming language they've written in. To reach the goal, we'll use the well-known freeware Geshi library.

Data storage

Assume that the statements are stored in a table with the following SQL definition:
Listing 1. SQL definition of the 'statement' table
CREATE TABLE statement (
  id                     int NOT NULL,
  statement_text         text NOT NULL,
  statement_language_id  int NOT NULL DEFAULT '0'
  /* Keys */
) ENGINE = InnoDB;

The 'statement_language_id' column contains the information on the programming language (C++, Java, SQL) used for the creating of code snippets stored in the 'statement_text' column in the following way: the '1' value of the 'statement_language_id' column means that the corresponding code fragment is written in C++, '2' - in Java, and '3' - in SQL.


Here are the steps involved in the implementation:

  • Copy third-party library files to your webserver (if necessary);
  • Include library files into the project;
  • Use library objects within the proper event handlers.

Each step will be covered in detail below.

Step 1

If the necessary library is absent on your webserver, you need to copy all the library files to any catalog of the computer the webserver is installed on.

Step 2

To use a PHP library in the generated app, we have to include one or several library files into the generated pages within the OnBeforePageExecute event handler. In the example case study, to use the Geshi library, it is enough to include the only file named geshi.php. Assuming that the library is placed in the geshi directory located a level above the generated application, we need to specify the event code as follows:

Listing 2. The OnBeforePageExecute event
include_once '../geshi/geshi.php';

Step 3

Now the library routines are ready to use. In this example we need to replace the content of the 'statement_text' column, so it's necessary to operate with the Geshi objects in the OnCustomRenderColumn event handler code.

Listing 3. The OnCustomRenderColumn event
    ($fieldName == 'statement_text') && 
    ($rowData['statement_language_id'] != 0)    
  switch ($rowData['statement_language_id']) {
    case 1: $language = 'cpp'; break;
    case 2: $language = 'java'; break;
    case 3: $language = 'sql'; 
  $source = $rowData['statement_text']; 
  $geshi = new GeSHi($source, $language);
  $customText = 
    '<div align="left">'.$geshi->parse_code().'</div>';
  $handled = 1;
The screenshot below displays how the event handler looks in PHP Generator.

The Events tab of the 'Statement' Page EditorPicture 3. The Events tab of the 'Statement' Page Editor and the OnCustomRenderColumn Event Editor


Now we can compare the result webpages without using the Geshi library and with implemented syntax highlighting:

Result webpagesPicture 4. Result webpages


Of course Geshi is not the only third-party library to be used with PHP Generator. Internet provides us with a lot of such things and all of them may be employed in the produced web applications.

For more information about a specific tool, see the appropriate page:

Prev Next