Choose your database:
AnySQL
MySQL
MS SQL Server
PostgreSQL
SQLite
Firebird
Oracle
SQL Anywhere
DB2
MaxDB

Subscribe to our news:
Partners
Testimonials
Rickey Steinke: "Folks, I wanted to drop a line and give you a fanatic thank you. I have a project due for my computer application course and without PHP Generator I never would have gotten it done with the professional results your product produced. My sincerest gratitude to each and every team member who brought this program to light".
Peter Robinson: "As a tech savvy company director, I wanted an inexpensive web based database application to manage all aspects of my business. As with most humans I find developing purely by CLI very hard and do not have the will or time to invest in improving my skills. I was looking to find a nice human friendly GUI to design and build my application, which is when I came across PHP Generator for MySQL.

Whilst you still need a great understanding of logic and a small amount of programming ability to get the specific results you require, I am very happy with the speed of progress I have been making with this invaluable tool.

With all the standard libraries included, this product makes normal requirements such as JavaScript form validation, lookup selectors, on click events, auto complete, detailed searches, multiformat exports, rss feeds and username security straight forward and quick.

Having any changes made via the GUI written to the web server at the click of a button makes testing out ideas quick and easy without fear of breaking your application.

To conclude, I couldn't find any other product on the market that came close to offering the amount of options this does, and I do hope that more products like this come out in the future, with the hope of eventually eradicating the need to program all together".

More

Add your opinion

SQL Maestro Group / Products / MySQL / PHP Generator for MySQL / 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

Abstract

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.

Problem

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 */
  PRIMARY KEY (id)
) 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.

Solution

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
if 
  (
    ($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

Result

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

Result webpagesPicture 4. Result webpages

Conclusion

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