Anda di halaman 1dari 151

PHP Generator for MySQL

User's guide

Copyright 2002-2014 SQL Maestro Group

PHP Generator for MySQL Help

Table of Contents
Foreword

I Welcome to PHP Generator for MySQL


1 System...................................................................................................................................
Requirements

2 Installation
...................................................................................................................................

3 How can
...................................................................................................................................
I purchase PHP Generator for MySQL?

4 License...................................................................................................................................
Agreement

5 About SQL
...................................................................................................................................
Maestro Group

6 What's...................................................................................................................................
new

10

11

II Getting started
1 How to...................................................................................................................................
connect to MySQL

12

2 Projects
...................................................................................................................................

16

3 Command
...................................................................................................................................
line options

17

4 Report...................................................................................................................................
sending

18

5 Shortcut
...................................................................................................................................
keys

19

20

III Configuring datasources


1 Tables...................................................................................................................................
and views

22

2 Custom
...................................................................................................................................
SQL queries

23

25

IV Customizing webpages
1 Page Editor
...................................................................................................................................

26

Columns
.......................................................................................................................................................... 26
Setting a lookup
.........................................................................................................................................................
editor
27
View properties
......................................................................................................................................................... 31
Edit properties
......................................................................................................................................................... 34
Multi-level autocomplete
.........................................................................................................................................................
editor
44
Inline Insert.........................................................................................................................................................
and Inline Edit
50
String templates
......................................................................................................................................................... 51
Uploading .........................................................................................................................................................
files to webserver
52
Master-Detail ..........................................................................................................................................................
Presentations
55
Events
.......................................................................................................................................................... 59
Global Events
......................................................................................................................................................... 60
OnAfterLogin
......................................................................................................................................... 61
OnBeforeUpdateRecord
......................................................................................................................................... 62
OnBeforeInsertRecord
......................................................................................................................................... 62
OnBeforeDeleteRecord
......................................................................................................................................... 63
Client Side.........................................................................................................................................................
Page Events
63
OnBeforePageLoad
......................................................................................................................................... 64
OnAfterPageLoad......................................................................................................................................... 64
OnInsertFormValidate
......................................................................................................................................... 65
OnEditFormValidate
......................................................................................................................................... 65

2014 SQL Maestro Group

Contents

II

OnInsertFormEditorValueChanged
......................................................................................................................................... 66
OnEditFormEditorValueChanged
......................................................................................................................................... 67
OnInsertFormLoaded
......................................................................................................................................... 69
OnEditFormLoaded
......................................................................................................................................... 70
Server Side.........................................................................................................................................................
Page Events
71
OnBeforePageExecute
......................................................................................................................................... 72
OnCustomRenderColumn
......................................................................................................................................... 72
OnCustomRenderPrintColumn
......................................................................................................................................... 75
OnCustomRenderExportColumn
......................................................................................................................................... 75
OnCustomHTMLHeader
......................................................................................................................................... 76
OnExtendedCustomDrawRow
......................................................................................................................................... 76
OnCustomRenderTotals
......................................................................................................................................... 78
OnGetCustomTemplate
......................................................................................................................................... 79
OnCustomDrawRow
......................................................................................................................................... 83
OnAfterUpdateRecord
......................................................................................................................................... 84
OnAfterDeleteRecord
......................................................................................................................................... 85
OnAfterInsertRecord
......................................................................................................................................... 85
OnBeforeUpdateRecord
......................................................................................................................................... 85
OnBeforeDeleteRecord
......................................................................................................................................... 86
OnBeforeInsertRecord
......................................................................................................................................... 86
Filter
.......................................................................................................................................................... 87
Page Properties
.......................................................................................................................................................... 88
Data Partitioning
.......................................................................................................................................................... 89
RSS
.......................................................................................................................................................... 91

2 Project...................................................................................................................................
Options

V Webpages appearance

94

96

1 Color schemes
...................................................................................................................................

99

2 Header
...................................................................................................................................
and Footer

100

3 Custom
...................................................................................................................................
CSS

101

4 Using...................................................................................................................................
templates

103

VI Security settings

105

1 Hard-coded
...................................................................................................................................
authorization

107

2 Table-based
...................................................................................................................................
authorization

109

3 Database
...................................................................................................................................
server authorization

111

4 Permission
...................................................................................................................................
manager

112

5 Record-level
...................................................................................................................................
security

115

VII Interface language

116

VIII Common generation options

118
120

IX Options
1 Application
...................................................................................................................................

121

Page
.......................................................................................................................................................... 121
Generation defaults
.......................................................................................................................................................... 124
Display formats
.......................................................................................................................................................... 125

2014 SQL Maestro Group

II

III

PHP Generator for MySQL Help


Output
.......................................................................................................................................................... 126
Confirmations
.......................................................................................................................................................... 127

2 Editors
...................................................................................................................................
& Viewers

129

General
.......................................................................................................................................................... 129
Display
.......................................................................................................................................................... 130
SQL highlight.......................................................................................................................................................... 131
XML highlight
.......................................................................................................................................................... 132
PHP highlight.......................................................................................................................................................... 133
Code Insight.......................................................................................................................................................... 134
Code Folding.......................................................................................................................................................... 135

3 Appearance
...................................................................................................................................

137

Bars and menus


.......................................................................................................................................................... 137
Trees and lists
.......................................................................................................................................................... 138
Edit controls.......................................................................................................................................................... 139
Check boxes.......................................................................................................................................................... 140
Buttons
.......................................................................................................................................................... 141
Page controls
.......................................................................................................................................................... 142
Group boxes.......................................................................................................................................................... 143
Splitters
.......................................................................................................................................................... 144

Index

146

2014 SQL Maestro Group

Welcome to PHP Generator for MySQL

Welcome to PHP Generator for MySQL


PHP Generator for MySQL is a tool for creating database-driven web applications
visually. It allows you to generate high-quality PHP scripts for working with MySQL tables,
views and queries through the web. You needn't have any programming background to
use it.
Key features:

Support for updatable SQL queries

Master-detail presentations

Event-driven content management

Client-side data validation

Custom pagination (display partitioning)

Data export to PDF, XML, CVS, Excel and Word

Support for hard-coded, table-based, and database server user authentication

Record-level security

Flexible appearance customization

Multi-language support

2014 SQL Maestro Group

23

55
59

115

116

96

89

105

1.1

PHP Generator for MySQL Help

System Requirements
Client environment

Pentium PC or higher;

Windows NT4/2000/XP/Vista/Windows 7/Windows 8;

256 MB RAM (512 MB recommended);

15 MB of free hard disk space;

SVGA-compatible video adapter;

Internet Explorer 9 or better.

Server environment
MySQL from 3.23 to 6.0;
Linux/Unix or Windows Web Server;
PHP 5.

2014 SQL Maestro Group

Welcome to PHP Generator for MySQL

1.2

Installation
To install PHP Generator for MySQL on your PC:
download the PHP Generator for MySQL distribution package from the download page
at our site;
run setup.exe from the local folder and follow the instructions of the installation
wizard;
find the PHP Generator for MySQL shortcut in the corresponding program group of
the Windows Start menu after the installation is completed.

2014 SQL Maestro Group

1.3

PHP Generator for MySQL Help

How can I purchase PHP Generator for MySQL?


Thank you for your interest in purchasing PHP Generator for MySQL Professional!
You can select licensing options and register PHP Generator for MySQL at its on-line
order page. It is possible to purchase on-line, by fax, mail, toll-free phone call, or place
a purchase order. We send the software activation key by email within 24 hours after
completion of the order process. If you have not received the activation key within this
period, please contact our sales department.
All our products and bundles are shipped with 12 months of free upgrades (minor and
major ones) or with 36 months of free upgrades for a quite small additional fee. After this
period you may renew your license for the next 12(36) months with a 50% discount.
PHP Generator for MySQL has a free 30-day trial. Upon purchasing the product you
confirm that you have tested it and you are completely satisfied with its current version.

To obtain technical support, please visit the appropriate section on our website or
contact us by email to support@sqlmaestro.com.

2014 SQL Maestro Group

Welcome to PHP Generator for MySQL

1.4

License Agreement
Notice to users: carefully read the following legal agreement. The use of the software
provided with this agreement (the "SOFTWARE") constitutes your acceptance of these
terms. If you do not agree to the terms of this agreement, do not install and/or use this
software. The use of this software is conditioned upon the user's compliance with the
terms of this agreement.
License grant. SQL Maestro Group grants you a license to use one copy of the
version of this SOFTWARE on any single hardware product for as many licenses as you
purchase. "You" means a company, an entity or an individual. "Use" means storing,
loading, installing, executing or displaying the SOFTWARE. You may not modify the
SOFTWARE or disable any licensing or control features of the SOFTWARE except as an
intended part of the SOFTWARE's programming features. This license is not
transferable to any other company, entity or individual. You may not publish any
registration information (serial numbers, registration keys, etc.) or pass it to any other
company, entity or individual.
Ownership. The SOFTWARE is owned and copyrighted by SQL Maestro Group. Your
license confers no title or ownership of the SOFTWARE and should not be construed as
a sale of any rights for the SOFTWARE.
Copyright. The SOFTWARE is protected by the United States copyright law and
international treaty provisions. You acknowledge that no title to the intellectual
property in the SOFTWARE is transferred to you. You further acknowledge that title
and full ownership rights to the SOFTWARE will remain the exclusive property of SQL
Maestro Group and you will not acquire any rights to the SOFTWARE except as
expressly set forth in this license. You agree that any copies of the SOFTWARE will
contain the same proprietary notices which appear on and in the SOFTWARE.
License and distribution. An unregistered copy of the SOFTWARE ("UNREGISTERED
SOFTWARE") may be used for evaluation purposes. The UNREGISTERED SOFTWARE
may be freely copied and distributed to other users for their evaluation. If you offer
this UNREGISTERED SOFTWARE installation package for download, then you agree to:
replace existing version of the UNREGISTERED SOFTWARE installation package with the
new package immediately after a new version of the SOFTWARE is released by SQL
Maestro Group, or
delete an obsolete version of the UNREGISTERED SOFTWARE installation package
immediately upon written email notice by SQL Maestro Group.
A registered copy of the SOFTWARE ("REGISTERED SOFTWARE") allows you to use the
SOFTWARE only on a single computer and only by a single user at a time. If you wish to
use the SOFTWARE for more than one user, you will need a separate license for each
individual user. You are allowed to make one copy of the REGISTERED SOFTWARE for
back-up purposes.
Reverse engineering. You affirm that you will not attempt to reverse compile,
modify, translate, or disassemble the SOFTWARE in whole or in part.
Unauthorized use. You may not use, copy, rent, lease, sell, modify, decompile,
disassemble, otherwise reverse engineer, or transfer the SOFTWARE except as
provided in this agreement. Any such unauthorized use shall result in immediate and

2014 SQL Maestro Group

PHP Generator for MySQL Help

automatic termination of this license.


No other warranties. SQL Maestro Group does not warrant that the SOFTWARE is
error-free. SQL Maestro Group disclaims all other warranties with respect to the
SOFTWARE, either express or implied, including but not limited to implied warranties of
merchantability, fitness for a particular purpose and noninfringement of third party
rights. Some jurisdictions do not allow the exclusion of implied warranties or limitations
on how long an implied warranty may last, or the exclusion or limitation of incidental or
consequential damages, so the above given limitations or exclusions may not apply to
you. This warranty gives you specific legal rights and you may also have other rights
which vary from jurisdiction to jurisdiction.
Limited warranty. This SOFTWARE is provided on an "AS IS" basis. SQL Maestro
Group disclaims all warranties relating to this SOFTWARE, whether expressed or
implied, including but not limited to any implied warranties of merchantability or fitness
for a particular purpose. Neither SQL Maestro Group nor anyone else who has been
involved in the creation, production, or delivery of this SOFTWARE shall be liable for
any indirect, consequential, or incidental damages arising out of the use or inability to
use such SOFTWARE, even if SQL Maestro Group has been advised of the possibility of
such damages or claims. The person using the SOFTWARE bears all risk as to the
quality and performance of the SOFTWARE.
Some jurisdictions do not allow limitation or exclusion of incidental or consequential
damages, so the above given limitations or exclusion may not apply to you to the extent
that liability is by law incapable of exclusion or restriction.
Severability. In the event of invalidity of any provision of this license, the parties
agree that such invalidity shall not affect the validity of the remaining portions of this
license.
No liability for consequential damages. In no event shall SQL Maestro Group or its
suppliers be liable to you for any consequential, special, incidental or indirect damages
of any kind arising out of the delivery, performance or use of the SOFTWARE, even if
SQL Maestro Group has been advised of the possibility of such damages. In no event
will SQL Maestro Group's liability for any claim, whether in contract, tort or any other
theory of liability, exceed the license fee paid by you, if any.
Entire agreement. This is the entire agreement between you and SQL Maestro Group
which supersedes any prior agreement or understanding, whether written or oral,
relating to the subject matter of this license.
Reserved rights. All rights not expressly granted here are reserved to SQL Maestro
Group.

2014 SQL Maestro Group

Welcome to PHP Generator for MySQL

1.5

About SQL Maestro Group


SQL Maestro Group is a privately-held company producing high-quality software for
database administrators and developers. The united team of eminently qualified
developers is pleased to create new software products for commercial, academic and
government customers worldwide. We do our best to design and develop products that
remove complexity, improve productivity, compress time frames, and increase database
performance and availability. We are glad to realize that our products take usual chores
upon themselves, so that our customers could have more time left for their creative work.
The company was founded in 2002 as an essential partner for every business that is
trying to harness the explosive growth in corporate data. SQL Maestro Group employs an
international team concentrating their efforts on cutting-edge DBA tools development.
The slogan of our company is The Shortest Path to SQL. It is aimed to denote that we
set to create easy-to-use products meant for those who appreciate comfort, friendly
program interface and support when working with SQL servers.

We are pleased to facilitate your job.

We aim at being of considerable assistance to our clients.

We feel contented doing our beloved work.

At present, our company offers a series of Windows GUI admin tools for SQL
management, control and development of the following servers: MySQL, Microsoft SQL
Server, PostgreSQL, Oracle, SQL Anywhere, DB2, SQLite, Firebird, and MaxDB. We
also produce universal tools to be used for administering any database engine accessible
via ODBC driver or OLE DB provider. Such products may be the clear-cut decision for
those who constantly work with several database servers.
SQL Maestro is the premier Windows GUI admin
tool for database development, management, and
control.
It provides you with the ability to perform all the
necessary database operations such as creating,
editing, copying, extracting and dropping database
objects; moreover, you can build queries visually,
execute queries and SQL scripts, view and edit
data including BLOBs, represent data as diagrams,
export and import data to/from most popular file
formats, manage users and their privileges (if
possible), and use a lot of other tools designed for
making your work with your server comfortable and
efficient.

2014 SQL Maestro Group

PHP Generator for MySQL Help

SQL PHP Generator is a powerful tool for creating


database-driven web applications visually. It allows
you to generate high-quality PHP scripts for
working with tables, views and queries through the
web. You
needn't
have
any programming
background to use it.

SQL Data Wizard is a high-capacity Windows GUI


utility for managing your data.
It provides you with a number of easy-to-use
wizards for performing
the
required
data
manipulation easily and quickly.The tool allows you
to convert any ADO-compatible database to the
Oracle database, export data from Oracle tables
and queries to most popular formats, import data
into the tables, and generate ASP.NET scripts for
the selected tables and queries.
SQL Code Factory is a premier GUI tool aimed at
the SQL queries and scripts development.
It allows you to manage SQL queries and scripts
using such useful features as code folding, code
completion and syntax highlighting, build query
visually, execute several queries at a time, execute
scripts from files, view and edit result data with
filtering, sorting and grouping abilities, export data
to as many as 14 file formats including Excel, RTF
and HTML, import data from Excel, CSV, XML and
text files, view and edit BLOBs in various way, build
diagrams based on Oracle data, and much more.
Data Sync is a powerful and easy-to-use tool for
database
contents
comparison
and
synchronization.
Such
tools
can
be useful
for
database
administrators, developers and testers that need a
quick, easy and reliable way to compare and
synchronize their data.

Service Center for MySQL is a multi-functional


Windows GUI utility for MySQL server maintenance
and data reservation.
It allows you to create tasks for backing your data
into a script, restoring data from a script,
analyzing, checking, repairing and optimizing
database tables. In addition to these functions,
Service Center for MySQL provides you with a
2014 SQL Maestro Group

Welcome to PHP Generator for MySQL

powerful task scheduler, an ability


scenarios and other useful features.

of

using

The software products are constantly optimized for the latest server versions support.
You can use the following contact information if necessary:
Our web-site

www.sqlmaestro.com

Postal address:

SQL Maestro Group


140 Broadway, Suite 706
New York City, New York 10005
United States

Thank you for your interest to our company!

2014 SQL Maestro Group

10

1.6

PHP Generator for MySQL Help

What's new
Please find out the latest PHP Generator for MySQL news at http://www.sqlmaestro.
com/products/mysql/phpgenerator/news/

2014 SQL Maestro Group

Getting started

11

Getting started
To create a database-driven web application,

Connect to the database

12

Configure datasources

to be available;

Customize data grids represented on web pages

Set other generation options


language

116

20

you want to work through the web;

118

25

to be created;

such as webpages appearance

96

and interface

Specify security settings

105

to protect your data from an unauthorized access.

PHP Generator for MySQL allows you to save and restore all the options set during a
session. All the session parameters may be saved and loaded to/from a project file.
Loaded settings may be edited if necessary. To run a wizard with a project, follow
More... > Load Project on the first wizard step and enter the name of the project file,
recently used projects are also available from this popup menu. Find out more about
working with Projects 16 .
2014 SQL Maestro Group

12

2.1

PHP Generator for MySQL Help

How to connect to MySQL


Connection properties
Set the connection parameters for the database you want the PHP scripts to work with.
Script connection properties
Specify here connection parameters for MySQL server relatively to the webserver. For
example, if your webserver and MySQL server are installed on the same computer, set Host

as localhost.
PHP Generator for MySQL allows you to connect to MySQL servers directly, via Secure
SHell (SSH) tunnel or HTTP tunnel.
Direct connection
It is the most natural and the most preferable connection mode. Use it each time it is
possible. Most of hosting companies allow direct connections to databases. However in
most cases you have to go to your control panel and add your home/office computer
IP address or domain name to Access List - list of IP addresses allowed accessing from
outside.
SSH tunnel connection
If your MySQL server does not allow direct connections from your remote
workstations, you can establish connection to an allowed intermediate SSH server and
forward all MySQL commands through the Secure SHell (SSH) tunnel.
More about SSH tunnel connection
To establish connection to intermediate SSH server and forward all MySQL
commands through the secure tunnel, you need to:
1. Check I can connect to the server directly or via SSH tunneling.
2. Follow the Configure SSH options link to open the SSH Options window.

2014 SQL Maestro Group

Getting started

3. Check Connect through the Secure Shell (SSH) tunnel and complete the
following fields:
Host name
Specify the host name or IP of your site. Note, that MySQL host name
always should be set relatively to the SSH server. For example, if both of
MySQL and SSH servers are located on the same computer, you should
specify localhost as Host name instead of server's external host name or IP
address.
Port number
Enter the port number for the SSH server.
4. Enter valid User name for the remote server and select the Authentication
method and set corresponding credentials.
Password-based
Set the password corresponding to the specified user.
Key-based
Specify the path to the Private key file with the corresponding Passphrase to
log in to the remote server. PHP Generator for MySQL accepts keys in ssh.
com or OpenSSH formats. To convert a private key from PuTTY's format to
one of the formats supported by our software, use the PuTTYgen utility that
can be freely downloaded from the PuTTY website.
Keyboard interactive
Keyboard authentication is the advanced form of password authentication,

2014 SQL Maestro Group

13

14

PHP Generator for MySQL Help

aimed specifically at the human operator as a client. During keyboard


authentication zero or more prompts (questions) is presented to the user.
The user should give the answer to each prompt (question). The number and
contents of the questions are virtually not limited, so certain types of
automated logins are also possible.
HTTP tunnel connection
HTTP tunneling is a technique used in conditions of restricted network connectivity
including firewalled networks, networks behind proxy servers, and NATs. It is the
slowest way and is recommended to use if the others are impossible.
More about connection via HTTP tunnel
To connect to a remote server using an HTTP tunnel, you need to:
1. Upload the connection PHP script to your website. The installation folder, usually C:
\Program Files\SQL Maestro Group\PHP Generator for MySQL, contains two scripts:
mysqli_tunnel.php and mysql_tunnel.php. We would recommend you to use the
mysqli_tunnel.php script always if possible as it operates through the MySQLi PHP
extension (available since PHP 5) while mysql_tunnel.php uses the original MySQL PHP
API that is deprecated as of PHP 5.5.
2. Select the I have to use HTTP tunneling radio button.
3. Enter the connection PHP script URL, e.g. www.yoursite.com/files/mysqli_tunnel.php.
You can test the connection before the profile is created. Just use Test script using
default browser to open connection script in your browser, enter all the required
connection parameters and click the Test connection button.

4. In case using of a proxy server use Configure tunnelling options to open the HTTP
tunnelling options window and specify your proxy server connection parameters and
HTTP authentication.

2014 SQL Maestro Group

Getting started

15

Note: You are actually connecting to your database through the PHP script on the
server, so in most cases the host/server name is "localhost" unless the target database
server is not installed on the same computer as the Web server.

Irrespectively of a connection mode you should specify common credentials as follows:


Host
The host name of the MySQL server.
Port number
The TCP/IP port to use if server is not localhost.
User name
The username used to connect to MySQL.
Password
The password for the user account on server.

2014 SQL Maestro Group

16

2.2

PHP Generator for MySQL Help

Projects
PHP Generator for MySQL allows you to save and restore all the options set during a
session. You need not to specify all options each time you work with the application
anew; instead you can load all settings from a project and change them if necessary.
Projects are very useful when working with PHP Generator. If you will close the
application without saving a project, all carefully adjusted settings will be lost. To set
the same options next time, you'll need to repeat the process step by step again while
with a project all the session parameters can be restored in a few mouse clicks.
To create a project, configure datasources and click More > Save Project at any next
step (Ctrl+S) or More > Save Project as... (Ctrl+Shift+S). All the settings you have
made will be saved to a file.
To restore previously saved settings from a project, click More > Load Project at the
first wizard step. Recently used projects are available from the More > Recent Projects
popup menu.

2014 SQL Maestro Group

Getting started

2.3

17

Command line options


PHP Generator for MySQL supports a number of command line options that make it
possible to fully automate PHP scripts creation. To generate the command line
automatically, load the project to be used or specify the generation options manually
and click More > Generate command line. The Command Line Builder allows you to save
the prepared line to clipboard or to a batch file.
The PHP Generator for MySQL command line syntax is as follows:
MyPHPGenerator[.exe] [<project_file_name>] [-o|output <output_directory>] [g|generate] [-h|help]
MyPHPGenerator[.exe]

The PHP Generator for MySQL program file.

<project_file_name>

The project

<output_directory>
-g|generate

A directory where file are generated to.


Generate without running the GUI application.

-h|help

Show help information.

16

with all the task's settings.

Examples
The examples below assume that you are entering the command lines in the PHP
Generator for MySQL program directory. Don't forget to enclose all paths and filenames
containing spaces in quotes.

myphpgenerator "C:\Templates\PHP_GENERATOR\MySQL\NBA_db.pgtm"

fbphpgenerator "C:\Templates\PHP_GENERATOR\Firebird\online_store.pgtf" -g -o
"C:\webserver\localhost"

2014 SQL Maestro Group

18

2.4

PHP Generator for MySQL Help

Report sending
To send a report to SQL Maestro support team, use the corresponding PHP Generator for
MySQL feature. To invoke the window, click More > Send report... .

Check the corresponding options to include project file, schema, and specified number of
the table records, add the problem description and click Send record to get the prepared
report in your default email client. In case you have no browser installed save the
prepared report to a file with the corresponding option and send it manually to
support@sqlmaestro.com as email attachment.

2014 SQL Maestro Group

Getting started

2.5

Shortcut keys
The following table describes the default shortcut keys in PHP Generator for MySQL.
Interface
Load project
Save project
Save project as...
Next step
Previous step
Generate PHP scripts
Exit
PHP Generator for MySQL help

2014 SQL Maestro Group

Ctrl+O
Ctrl+S
Ctrl+Shift+S
Shift+N
Shift+B
Shift+R
Alt+F4
Shift+H

19

20

PHP Generator for MySQL Help

Configuring datasources
PHP Generator for MySQL creates webpages aimed at interaction with MySQL tables,
views, and queries throw the web. Each webpage contains a grid with data of according
datasource supplied with abilities to view, edit, filter, sort, delete, and others.
Adding tables and views
To add a table or a view, open the Select object
button.

22

window with the corresponding

Adding queries
To add a query, type the query text in the Query editor 23 or load it from .sql file with
More > Load query from file... Moreover you can use queries stored a single .qrp file
(query repository). This feature may be extremely useful if you need to share a set of
the same queries between several different projects. To save/load queries to/from a
single file, use More > Save all queries as repository / Load query repository items from
the More button menu accordingly.
Invalid queries
The wizard automatically validates objects and displays names of invalid queries in red.
The basic rules of queries usage in PHP Generator projects are covered in the
corresponding topic 23 .
Primary keys
The wizard automatically inspects all data objects for unique identifiers that are
necessary for add, edit, and delete operations. It marks objects without primary key
constraints with No key columns label and asks a confirmation 127 on moving to the next
step. It's recommended to specify a single column or a set of columns that uniquely
identifies each record in the view/query to expedite the work of the generated
application. It's optional but preferable.

2014 SQL Maestro Group

Configuring datasources

21

By default, each script has settings defined by the application options 121 . Of course,
you can change them later, but it's useful to setup the generation rules in accordance
with settings of the most webpages to reduce further adjustments.

2014 SQL Maestro Group

22

3.1

PHP Generator for MySQL Help

Tables and views


To specify source database objects for working through the web, pick the objects in the
Select objects tab. To choose several objects at a time, select them using Ctrl and
Shift keys, then click Mark selected.

2014 SQL Maestro Group

Configuring datasources

3.2

23

Custom SQL queries


To add a query within the editor, use the Create Query button or select the
corresponding popup menu item, specify the query name and text, and click OK.
Rules for creating queries used by PHP Generator
All queries must satisfy the simple requirement: the following query must be correct.
select * from
(
QUERY_TEXT_YOU_ENTERED
) an_alias

This happens because the software uses similar queries for internal needs. In case such
SQL expression is not valid, the wizard marks the query as invalid and displays its name
in red.
To meet this requirement, make sure that all the columns in the result dataset have
unique aliases. For example, the following query works fine itself, but returns a dataset
with two columns named id:
SELECT
table1.*,
table2.*
FROM table1, table2
WHERE table1.id = table2.id;

This is the reason the wizard marks this query as invalid. To solve the problem, provide
these columns with unique aliases:
SELECT
table1.id as table1_id,
table2.id as table2_id
FROM table1, table2
WHERE table1.id = table2.id;

Creating updatable datasets (For Professional Edition Only)


To get an updatable dataset based on an SQL query, you have to provide up to three
SQL queries: UPDATE, INSERT, and DELETE to be able to modify, add and remove
records accordingly. The first query provides an UPDATE statement for modifying existing
records; the second query provides an INSERT statement to add a new record to the
tables; and the third one provides a DELETE statement to remove the records. Each of
these queries can contain several parameterized statements that use parameters like :
field_name.
Example
Assume that we have the following SELECT statement:
SELECT
id,
first_name,
last_name
FROM customer
WHERE last_name LIKE 'A%'

2014 SQL Maestro Group

24

PHP Generator for MySQL Help

To create an updatable dataset based on this query, INSERT, UPDATE and DELETE
statements can be specified as follows:
INSERT INTO
customer
VALUES (:id,

:first_name,

:last_name);

UPDATE customer
SET
id = :id,
first_name = :first_name,
last_name = :last_name
WHERE id = :OLD_id;
DELETE FROM customer
WHERE id = :id;

2014 SQL Maestro Group

Customizing webpages

25

Customizing webpages
Pages
This tab contains the list of webpages to be created. Each page is based on a
datasource defined on previous steps and is created with default settings defined by the
application options 121 . Use the Edit button to edit settings of a concrete webpage with
the Page editor 26 . To exclude a webpage from the navigation menu of generated
pages, uncheck the Include into menu option. Note, that the pages will be displayed at
the navigation menu on the generated pages in the same order as they are disposed in
the grid. To reorder the webpages, use the corresponding link of the popup menu. The
Reset and Reset all buttons allow you to setup webpages properties according to the
generation rules 124 .
Details
This tab contains detail presentations 55 for the page selected at the Pages tab. The
detail presentations are created according to the master-detail relationships (if Setup
details by foreign key option 124 is enabled). Use the Reset and Reset all buttons to
setup detail pages properties according to the project options 94 .
Project Options
To specify default setting 94 to be applied to each generated page, follow the Setup
project options to configure default page settings link. This properties may be edited for
the concrete page within the Page Properties 88 window.

2014 SQL Maestro Group

26

4.1

PHP Generator for MySQL Help

Page Editor
Columns 26
Use this tab to setup columns to be included into the result pages (List, View, Edit,
Insert, etc.), column captions, data representation on viewing and editing, lookup
options and more.
Details 55
Use this tab to adjust the page detail presentations and setup detail pages properties.
Events 59
Set here the fragments of PHP code to be executed before or after a record was added,
edited, deleted, etc.
Filter 87
Use this tab to reduce the number of records available at the generated page.
Use the Page Properties 88 window to setup common page properties such as view/edit/
delete/filter/export abilities, pagination options, page header, and more.
The Data Partitioning 89 wizard allows you to create a custom pagination i.e. split the
records on the generated page by a specified criteria.

4.1.1

Columns
For each datasource PHP Generator for MySQL creates a bunch of presentations: the
List presentation (data grid), the View presentation (on a record viewing), the Edit
presentation (on a record editing), etc. The Columns tab of Page Editor allows you to
adjust the presentations' appearance.
The General tab allows you to configure column properties for all the presentations. The
properties for a concrete presentation can be specified at the corresponding tab.
Include/exclude columns to/from a concrete presentation (List, View, Edit, etc.) using
corresponding boxes. Use Include into all presentations / Exclude from all presentations
command from the tab's popup menu to get the column listed/unlisted on all generated
pages.
To restore default column options, use the Reset column link from the tab's popup menu.
Specify the column caption and set a lookup editor 27 for the column if necessary. By
default, PHP Generator for MySQL enables a lookup editor for columns linked by a foreign
key with a single column from another table (if Setup lookups by foreign key option 124 is
enabled).
The View 31 properties determine how the column is displayed on the List, View, Print
and Export pages.
The Edit
pages.

34

properties define how the column is represented on the Edit and Insert

2014 SQL Maestro Group

Customizing webpages

27

The Inline Edit, Inline Insert 50 properties determine whether the column will be
available for inline adding/editing and how it will be represented.
To reorder columns, use the grid's popup menu of a concrete presentation. The order
of columns at the General tab remains
unchanged as it is possible to have different column order for different presentation.

4.1.1.1

Setting a lookup editor


Lookup editors are used in case you want to select for a field a value that corresponds
to a pre-defined value e.g. a record of another dataset. PHP Generator for MySQL
provides you with two types of lookup editors: Radio group or Combo box. Select Radio
group as the column's Edit properties if the number of the column values is quite little.
Setting a lookup editor bound to a data source (table, view, query)
If you create a PHP script for taking orders, the 'Orders' table will generally have a field
hosting a number indicating the customer who made the order. Working directly with the
customer number is not the most natural way; most users will prefer to work with

2014 SQL Maestro Group

28

PHP Generator for MySQL Help

customer names. However, in the database the customers' names are stored in a
different table to avoid duplicating the customer data for each order by the same
customer. To get around such a situation, you can enable a lookup editor:
check the Use lookup box;
select the foreign table/view/query as Data Source;
specify the field with the same data as Link field;
set the field with data to appear in the lookup editor as Display field;
By default, PHP Generator for MySQL enables a combo box lookup editor for a column
linked by a foreign key with a single column from another table (if Setup lookups by
foreign key option 124 is enabled).
Using Filter condition
Filter condition allows you to reduce the list of values represented in the lookup editor
with a specified criterion. This condition corresponds to the WHERE clause applied to the
data source (you must not add the WHERE keyword to beginning of the condition). The
following operators can be used in this clause: =,<> (!=), >, <, >=, <=, BETWEEN, LIKE,
IN. It is also possible to use predefined variables like %CURRENT_USER_NAME%.
Example 1
To enable a lookup editor with a list of USA cities (the corresponding value of
"country_id" is 103) named like Da*, specify the following condition: country_id = 103
AND city LIKE 'Da%'

Example 2
Suppose we have a table that contains a column 'owner' with owner information. To set
a lookup editor with the list of values owned by the current user, specify the filter
condition as follows: owner = %CURRENT_USER_NAME%
Setting a lookup editor represented data of several columns
To create such lookup editor, create a query with all the necessary data concatenated
into a single column and specify the query as Data Source. A complete example can be
found below.
Example
Suppose we have three tables: 'employee' with a list of office employees, 'job' with
employees' job titles and salaries, and 'department' with a list of office departments.
See definitions here
CREATE TABLE employee (
EMP_NO
integer NOT
FIRST_NAME
varchar(15)
LAST_NAME
varchar(20)
JOB_CODE
integer NOT
DEPT_NO
integer NOT
)

NULL PRIMARY KEY,


NOT NULL,
NOT NULL,
NULL,
NULL

CREATE TABLE job (


JOB_CODE
integer NOT NULL PRIMARY KEY,
JOB_TITLE
varchar(25) NOT NULL,
SALARY
real NOT NULL
)

2014 SQL Maestro Group

Customizing webpages

29

CREATE TABLE department (


DEPT_NO
integer NOT NULL PRIMARY KEY,
DEPARTMENT varchar(20) NOT NULL,
HEAD_DEPT
integer,
MNGR_NO
integer,
BUDGET
real,
LOCATION
integer,
PHONE_NO
char(20)
)

To enable a lookup editor for the 'HEAD_DEPT' field of the 'department' table
representing first name, last name, and job title of the employee, follow the steps above
with the following query text:
SELECT
e.EMP_NO as ID,
CONCAT(e.FIRST_NAME, ' ', e.LAST_NAME, ', ', j.JOB_TITLE) as FULL_NAME
FROM employee e,
job j
WHERE e.JOB_CODE = j.JOB_CODE

2014 SQL Maestro Group

30

PHP Generator for MySQL Help

Setting a lookup editor bound to a custom value list


To create a lookup editor bound to a custom value list i.e. to a list of values that are
not stored in a database table and cannot be retrieved by a query, process as follows:
Click the ellipsis button next to the "Edit properties";
Enter

the

list

of

the

allowed

values

in

pairs

2014 SQL Maestro Group

Customizing webpages

an_allowed_value=value_to_be_represented

31

separated by a comma (Example:

1=One,2=Two).

By default, PHP Generator for MySQL creates lookup editors described above for columns
based on enumeration data types.

4.1.1.2

View properties
Use the View options to define the way the column data are represented on generated
webpages.

2014 SQL Maestro Group

32

PHP Generator for MySQL Help

Use Display properties to set the type of data representation and format options (text
alignment, image size, and so on). The available representations with the corresponding
format options are shown in the table below. Format options are specified within the
corresponding dialog opened by the ellipsis button next to the Display properties. By
default, the format is the same as it is set at the Project options 125 .
Along with available format options you can define your own ones with the Custom
attributes option. This option allows you to specify the content of standard HTML style
tag applied to the column data. For example, to set the font color and size of the
column, enter style="color:red;font-size:20px;" as Custom attributes. To implement
more difficult data representation, especially for conditional data formatting, it's
recommended to use the OnExtendedCustomDrawRow 76 event.
Available
representations
Text

Additional options

Result

It's possible to set such style


attributes as text alignment, and
font options (bold, italic). The Max
length value is the max number of
signs to be visible on
the
generated webpage. You can also
allow to replace CR+LF by <BR>,
to use HTML and Word wrapping
and specify several format options

2014 SQL Maestro Group

Customizing webpages

to be applied to the column data


depending of data type (Number,
Percent, String, Currency).
DateTime

Select the
format.

type

of

date time

Image

If BLOB data will be represented as


images, specify the size of all the
column images with Resize type
and Height and Width fields. Image
hints are set with templates 51 .
To resize images, you need to
have
the
appropriate
PHP
extension installed.

File download

If BLOB data will be represented as


file downloads, set a Download file
name and a Content type using
templates 51 . The Content type
value is optional. To change the
download image, generate the
project and change the download.
gif file in the images folder.

Checkbox

There are three display types of


boolean data: check box controls,
custom images,
custom
text
values.
Select the
necessary
option and specify the custom
information (TRUE/FALSE captions
or images).

External
External
image

file,

To represent data in such a way,


specify the Source prefix and
Source suffix.
Example
Suppose there is a
column with such data:
firebird_maestro,
sqlite_maestro,

'product'

There are image files with the


following paths:
D:\Images
\firebird_maestro_62x62.jpg
D:\Images\sqlite_maestro_62x62.
jpg
To represent these images at the
'product' column on the generated
page, Select External Image as
View Properties and set
2014 SQL Maestro Group

33

34

PHP Generator for MySQL Help

Source prefix=D:\Images\
Source suffix=_62x62.jpg
Display as hyperlink
To represent the column's data as hyperlink, check the Display as hyperlink option and
specify the HREF Template 51 . Target controls where the new document is displayed
when a user follows the link.
_blank
_parent

_self

_top

opens the new document in a new window.


is used in the situation where a frameset file is nested inside
another frameset file. A link in one of the inner frameset
documents which uses "_parent" will load the new document where
the inner frameset file had been.
puts the new document in the same window and frame as the
current document. "_self" works the same as if you had not used
TARGET at all.
loads the linked document in the topmost frame... that is, the new
page fills the entire window.

Use the Header hint field to specify the the column caption's hint. By default, it is a
comment to the table/view column.
Fixed column width
To set a fixed width of the grid, check the Fixed width, specify the Width, and select
the Units.
Units
em
px
in
cm
mm
pt
pc

Meaning
The 'font-size' of the relevant font.
(pixels) Relative to the viewing device.
(inches) 1 inch is equal to 2.54 centimeters.
Centimeters
Millimeters
(points) The points used by CSS 2.1 are equal to 1/72nd of an inch.
(picas) 1 pica is equal to 12 points.

The Totals option allows you to enable a grid footer to display summaries (Sum,
Average, Count, etc) for all or selected grid columns.
4.1.1.3

Edit properties
Use the Edit properties to define the way the column data to be represented on the Edit
and Insert pages and set additional options within the dialog opened by the ellipsis
button next to the Edit properties.
Use Style custom attributes to specify the appearance of inserting data. For example,
to set the font color of the column, enter style="color: red;" as Custom attributes.
The Read only fields cannot be modified. However, a user can tab to it, highlight it, and
copy the text from it. Check the Required box if the field is mandatory. Set also the
Default value for the column (for adding new record only). PHP Generator for MySQL
supports some environment valiables such as CURRENT_USER_ID, CURRENT_USER_NAME,
UNIQUE_ID.

2014 SQL Maestro Group

Customizing webpages

Additional format-specific options


Ava
ila
ble
edi
tor
s

Additional
options

Tex
t

Set
the
Size
of
the
text
block. The
Max
length
value
is
the max
number of
signs
to
enter.

Co
mb
o
box

Enter the
list of the
allowed
values in
pairs
an_allowe
d_value=v
alue_to_b
e_represe
nted
separated
by
a
comma
(Example:
1=One,2=
Two).
Specify
the mostfrequently
used
values to
be always
displayed
at the top
of the list.
To
do
this, click
the ellipsis
button
next
to
the Most
frequently

2014 SQL Maestro Group

Editor appearance

35

36

PHP Generator for MySQL Help

used
values
and
add
values
within the
correspon
ding
window.
You
can
also
enable a
lookup
editor
based
that
contains
one
or
more table
columns.
For
this
purpose,
specify
Item
caption
template
51 .
Rad
io
gr
ou
p

Enter the
list of the
allowed
values
in
the same
way as for
Combo box
editor.

Aut
oco
mpl
ete
edit
or

Use
this
editor type
as lookup
editor
to
work with
a quantity
of records.

2014 SQL Maestro Group

Customizing webpages

Mul
tileve
l
aut
oco
mpl
ete
edit
or

The
control is
based on
cascading
dropdown lists
and allows
users
to
select
a
value from
a long list
step-bystep. For
example,
when we
select
a
country in
the
Country
dropdown list,
it
will
populate
the
City
dropdown list
according
to
the
country
selected,
and
so
on.
To
find
out
more
instructio
ns
use
the
correspon
ding topic
44 .
Specify
the levels
in
the
dialog
opened by
the ellipsis
button.
To set a
new level,
enter the
level

2014 SQL Maestro Group

37

38

PHP Generator for MySQL Help

caption,
parent
data
source (a
table that
contains
data
to
be
displayed
on
the
next level
of
the
editor),
and
the
name
of
the
column
the data
to
be
displayed.
Key field
of
the
parent
data
source
and child
field
to
filter must
contain
the same
values.
Che
ck
box

The editor
is set for
boolean
columns by
default.

Che
ck
box
gro
up

Enter the
list of the
allowed
values
in
the same
way as for
Combo box
editor.

2014 SQL Maestro Group

Customizing webpages

Dat
eTi
me

Check off
the Show
time box
to
represent
the only
date. By
default,
the
format of
the
column's
data
is
the same
as it is
set at the
Project
options 125
. Use the
DateTime
format
field
to
setup
format of
the
current
column.

Tim
e

This
editor
is
used
by
default for
columns
that store
time-ofday
values.

Spin
edit

This
editor
type
allows you
to set the
constraint
s
(Min
value,
Max value
) on the
entered
data.

2014 SQL Maestro Group

39

40

PHP Generator for MySQL Help

Mas
k
edit

Use
the
edit
control to
define an
edit
box
that limits
the user
to
a
specific
format
and
accepts
only valid
character
s.
For
example,
you
can
define an
edit
box
for
telephone
numbers
setting
999-9999999
as
the mask
of
the
editor. In
this case
the
created
data
entry field
accepts
only
numeric
input and
if a user
then tries
to enter a
letter
in
this
edit
box, the
applicatio
n will not
accept it.

2014 SQL Maestro Group

Customizing webpages

Tex
t
are
a

Define the
size
of
area visible
text
part
using
the
Column
count and
Row count
fields.

Ht
ml
Wy
si
wy
g

Use
the
editor
to
provide
PHP
scripts'
users with
the ability
to directly
manipulate
the layout
of a HTML
data
stored in
the
column,
without
having to
type
or
remember
names of
layout
commands
.

Pas
swo
rd

Displays
the field as
a
masked
textbox.

File
uplo
ad

If
BLOB
data will
be edited
with such
editor,
you
can
limit
the
size of an
uploading
file
with
the
Use
file
size
limitation
option and
the
Max

2014 SQL Maestro Group

41

42

PHP Generator for MySQL Help

file
size
field.
To
store
names,
types,
and sizes
of
uploaded
files,
specify
the proper
columns
as
File
name
field, File
type field,
and
File
size field
respective
ly.
Ima
ge
uplo
ad

If
BLOB
data will
be edited
as Image
uploads,
you
can
limit
the
size of an
uploading
file,
specify
columns
to
store
names,
types,
and sizes
of
uploaded
files in the
same way
as for File
upload.
To
limit
the
size
of
uploaded
images,
use
the
Use image
size
limitation
options,

2014 SQL Maestro Group

Customizing webpages

and
set
the
necessary
Max
width and
Max
height.
Upl
oa
d
file
to
fol
de
r,
Upl
oa
d
im
ag
e
to
fol
de
r

To
use
the
column to
store
paths to
uploaded
files,
setup the
Folder to
upload
and
the
File name
using
templates
51 .
To
use
a
random
number as
filename,
check the
Generate
random
filename
box.
The
Generate
thumbnail
option
allows you
to
save
resized
copies of
uploaded
images to
a
specified
catalog.
To do it,
check the
correspon
ding box,
specify
the Field
name the

2014 SQL Maestro Group

43

44

PHP Generator for MySQL Help

thumbnail
path
to
be saved
to,
set
the Folder
to upload
and
the
name
of
the
created
file
(It's
possible
to
use
templates
51
or
random
file
names)
and
submit
the resize
rules.
4.1.1.4

Multi-level autocomplete editor


The editor appearance
Multi-level autocomplete editor is based on cascading drop-down lists and allows users
to select a value from a long list step-by-step. The picture below shows how it works:
first we select a country from the Country drop-down list, then we select a city from
the list of cities related to the selected country and select an address from the list of
addresses in this city (for the second example).

The number of levels is not limited, so you can create any similar editor using the same
technique as described below.
Database schema requirements
To create a two-level editor, you need to have three tables: the first table is actually
the table that is the data source for the generated webpage (Address in the example
above). The column the multi-level editor is creating for must refer to the primary key
2014 SQL Maestro Group

Customizing webpages

45

column of the second table. The second table is the parent table to the first table (in
our case it is City), and the third table is the parent table to the second one (Country).
The foreign key constraints are not required but highly recommended to enforce the
referential integrity at the database level.
To create a three-level editor, you need to have four tables linked with each other as
described above, and so on.
Example
Let's consider how to implement a three-level editor. Suppose we have the following
tables:

Our goal is to create a three-level editor like this:

to allow users of the generated web app to select the customer address in the simplest
way.
1. Open the Page Editor for the page based on the Customer table, select the
Address_id column, and specify its lookup properties 27 . If you have defined a foreign
key constraint for this column in the database and the Setup lookup by foreign key 124
option is enabled, these properties will be set automatically.

2014 SQL Maestro Group

46

PHP Generator for MySQL Help

2. Select Multi-level autocomplete editor as Edit properties for this column (see the
picture above), then press the ellipsis button. A dialog window will be opened.

2014 SQL Maestro Group

Customizing webpages

47

3. Now it's time to add the first level. Click Add level and enter values in the Add filter
dialog window as follows:

2014 SQL Maestro Group

48

PHP Generator for MySQL Help

Click OK to save the changes. The list of levels now looks as follows:

2014 SQL Maestro Group

Customizing webpages

4. Add the next level in the same way:

2014 SQL Maestro Group

49

50

PHP Generator for MySQL Help

Click OK in the Edit properties window to save all the settings and return to the Page
Editor.
4.1.1.5

Inline Insert and Inline Edit


The Inline Insert/Inline Edit features allow a user to add/edit the content of the
generated page quickly without having to switch modes or screens. All work is done on
the same interface which helps the user maintain context.
To enable the inline inserting/editing:

Make sure that the Insert (Edit) ability option is set as Inline at the Page
properties

88

Specify the columns to be available for inline inserting (editing) at the Inline
Insert (Inline Edit) tab of the Page Editor

26

If necessary define the way the column data to be represented on inserting/


editing. By default, it is represented as it is set at the Edit/Insert properties of
the General

26

tab.

2014 SQL Maestro Group

Customizing webpages

4.1.1.6

51

String templates
String templates are used by PHP Generator for MySQL on setting HREF templates, hints,
etc. The strings may contain column names enclosed by %.
Examples:
1. Suppose a table 'team' stores various info about NBA teams. The table has 'caption'
column with such data:
maverics

2014 SQL Maestro Group

52

PHP Generator for MySQL Help

cavaliers
To create links to the team home pages:
http://www.nba.com/maverics/
http://www.nba.com/cavaliers/
set the HREF template
http://www.nba.com/%caption%/
2. Suppose there is a table 'employee' storing employee info. The table has 'first_name'
and 'last_name' columns with such data:
Forest Gump
Sara Connor
To add such hints to their photos on the generated webpage:
Forest Gump Photo
Sara Connor Photo
Specify the hint template:
%first_name% %last_name% Photo
4.1.1.7

Uploading files to webserver


There are two ways to store files on a webserver:
1. Store files directly in the database (in BLOB columns).
2. Store files on a disk. Database stores the paths to the files in this case.
Uploading files to be stored in a database
To allow the uploading of files and images to a BLOB column, select File Upload or Image
Upload at the column's Edit properties and Click the ellipsis button next to Edit properties
and set the additional parameters of the uploading.

2014 SQL Maestro Group

Customizing webpages

53

To limit the size of uploading files, check the Use file size limitation option and specify
the Max file size.
To store original names, types, and sizes of the uploaded files, specify the proper
columns as File name field, File type field, and File size field respectively. (Optional)
For image uploads you can limit the dimensions of uploaded images. For this purpose,
check the Use image size limitation options, and set the necessary Max width and Max
height.
Example
To allow uploading images which size is not greater than 200Kb, width is not greater
than 600px and height is not greater than 400px and to save the original file names to
the file_name column, specify the Edit properties as follows:

2014 SQL Maestro Group

54

PHP Generator for MySQL Help

Uploading files to be stored on a disk


To allow the generated PHP script to upload files to your webserver and save their paths
in your database, select Upload file to folder or Upload image to folder at the column's
Edit properties and click the ellipsis button next to Edit properties and set the additional
parameters of the uploading.

Specify the folder to upload and names for uploaded files: a random number or a new
name composed of original file name, original file extension and the size of original file.
Example:
Suppose we have files:
sqlite_maestro.exe (14563609 Bytes)
mysql_maestro.exe (27241901 Bytes)

2014 SQL Maestro Group

Customizing webpages

55

To upload them using the generated PHP script to the data/files/ folder as
sqlite_maestro (14563609).exe
mysql_maestro (27241901).exe
Specify the Edit properties as follows:

4.1.2

Master-Detail Presentations
Master-detail presentations allow you to navigate a webpage based on a specific table,
and at the same time for each selected record (master record) see the associated
records from other related tables (details). So, browsing the page representing product
information, you can see all the orders corresponding to the necessary products;
working with list of countries - to inspect cities of specific countries as on the picture
below.

You can also create nested master-detail presentations when you can see the "details
of details". On the picture below the webpage with a list of countries is represented, for
any country all the corresponding cities may be browsed with one click and at the same
time it's possible to see all addresses of customers living in specific cities.

2014 SQL Maestro Group

56

PHP Generator for MySQL Help

To add a master-detail relation within PHP Generator for MySQL means to provide each
record of the result webpage with an ability to browse all records associated with this
record on a separate Details page as well as with an ability to view the 20 first such
records on the result page directly. To open the corresponding Details page, follow the
full view link.
Database schema requirements
To create a two-level master-detail presentation, you need to have two tables with a
parent-child relationship. The foreign key constraints are not required but highly
recommended to enforce the referential integrity at the database level.
Realization
There are two ways to provide the result webpage with a master-detail presentation:
The tables are tables linked with a foreign key. In case the Setup details by foreign
key 124 option is enabled, the detail relation will be set automatically.

2014 SQL Maestro Group

Customizing webpages

57

The foreign key constraint between theses tables haven't been defined.
1. Open the Page Editor for the page based on the master table and go to the Details
tab.
2. Click the Add... item of the tab's popup menu.

2014 SQL Maestro Group

58

PHP Generator for MySQL Help

3. Set the relation properties to the child table: select this table as Detail data source,
and specify the columns with similar data as Master field (select from the list of parent
table columns) and Detail field (select from the list of child table columns).

2014 SQL Maestro Group

Customizing webpages

59

4. After the fields are completed use the Add button and then click OK.
To specify the details appearance, use the Edit... item of the corresponding popup menu
and set options in a usual way 26 .
To create a nested master-detail presentation, use the same technique as described
above (the case the foreign key constraint is not defined).

4.1.3

Events
PHP Generator for MySQL allows you to supply the generated applications with an
additional functionality with the help of event handlers. Event handlers are fragments of
PHP/Javascript code executed at the appointed time. This feature provides you with
wide opportunities: for example, you can equip webpages with tracking of user activity,
completely redesign any created page, supply the application with the power of thirdpart libraries, etc.
All evens supported by PHP Generator for MySQL may be divided by the scope the
events are fired on (possible options are all generated webpages (global events) or a
certain webpage (page-specific events)); and by the side the event handlers are
executed on: the webserver (written on PHP) or browsers (written on Javascript).
Global Events

60

Page Events executed at Client Side


Page Events executed at Server Side

2014 SQL Maestro Group

63
71

60

PHP Generator for MySQL Help

To add or modify an event handler:


open the editor

26

of a webpage the event to be fired on (for Page events) or the

Project Options

94

(for Global events);

go to the Events tab;


select the desired event from the list and double-click the appropriate line in the
grid (it is also possible to use popup menu or Ctrl+Enter);
enter your PHP/Javascript code in the text area.
To disable any specified event temporarily, use the corresponding checkboxes at the
Events tab of the according Page Editor 26 (for Page events) or the Project Options 94
(for Global events).
4.1.3.1

Global Events
Handlers of global events contain pieces of PHP code that are not specific for any page
i.e. these events are fired on all the generated webpages.
OnAfterLogin

61

OnBeforeUpdateRecord
OnBeforeInsertRecord
OnBeforeDeleteRecord

62

62
63

To specify a handler for a global event, open the project options 94 window, select the
appropriate node in the tree, and enter your code. The Events tab of the dialog allows
you to temporarily disable a certain event.

2014 SQL Maestro Group

Customizing webpages

61

4.1.3.1.1 OnAfterLogin

This event occurs after a user is successfully logged in into the application.
Signature:
function

OnCustomHTMLHeader

($userName,

$connection)

Parameters:
$userName

A variable storing the name of logged user.

$connection

An instance of the Connection class which ExecSQL


method allows to execute specified SQL scripts.

Example:
Let's show how to use this event for tracking the user activity. The code snippet below
inserts a new record containing user name and the connection time into the 'log' table.
$connection->ExecSQL("INSERT INTO log(user_name,
VALUES ('$userName', CURRENT_TIMESTAMP)");

2014 SQL Maestro Group

log_date)

62

PHP Generator for MySQL Help

4.1.3.1.2 OnBeforeUpdateRecord

This event occurs when the Update command is executed, but before the actual
update. It is often used to cancel the update operation.
Signature:
function

OnBeforeUpdateRecord

( $page, &$rowData, &$cancel, &$message, $tableName)

Parameters:
$page

An instance of the Page class declared in components/


page.php.

$rowData

An associative array of values that corresponds to the


currently processed row.

$cancel

Set this parameter to 'true' to cancel the update


operation.

$message

Use this string to specify a message to be displayed


after the operation is completed (or canceled).

$tableName

The name of processed table.

Example 1:
To prevent data from updating, place the following code to the event body.
$cancel = true;
$message = 'Updating is disabled.';

Example 2:
You can also restrict data changes with this event handler. The code below prevents
the update of the 'city' table by a user logged as guest.
$userName
=
$page->GetEnvVar('CURRENT_USER_NAME');
if (($tableName == "`city`") &&
($userName = guest))
{
$message = 'No update possible because the guest has no permission to change this table.';
$cancel = true;
}

See also: OnBeforeInsertRecord


(page event) 85 .

62

, OnBeforeDeleteRecord

63

, OnBeforeUpdateRecord

4.1.3.1.3 OnBeforeInsertRecord

This event occurs when the Insert command is executed, but before the actual
insertion. It is often used to cancel the insert operation.
Signature:
function

OnBeforeUpdateRecord

( $page, &$rowData, &$cancel, &$message, $tableName)

Parameters:
$page

An instance of the Page class declared in components/


page.php.

$rowData

An associative array of values that corresponds to the


currently processed row.

2014 SQL Maestro Group

Customizing webpages

$cancel

The value indicates whether the operation should be


canceled.

$message

Use this string to specify the message to be displayed


after the operation is completed (or canceled).

$tableName

The name of processed table.

63

Example:
To disallow adding of new records, place the following code to the event body.
$cancel = true;
$message = 'Inserting is disabled.';

See also: OnBeforeUpdateRecord


(page event) 86 .

62

, OnBeforeDeleteRecord

63

, OnBeforeInsertRecord

4.1.3.1.4 OnBeforeDeleteRecord

This event occurs when the Delete command is executed, but before the actual
deletion. It is often used to cancel the delete operation.
Signature:
function

OnBeforeDeleteRecord

( $page, &$rowData, &$cancel, &$message, $tableName)

Parameters:
$page

An instance of the Page class declared in components/


page.php.

$rowData

An associative array of values that corresponds to the


currently processed row.

$cancel

The value indicates whether the operation should be


canceled.

$message

Use this string to specify the message to be displayed


after the operation is completed (or canceled).

$tableName

The name of processed table.

Example:
To protect records from deletion, add the following lines to this event body.
$cancel = true;
$message = 'Deleting is disabled.';

See also: OnBeforeUpdateRecord


(page event) 86 .
4.1.3.2

62

, OnBeforeInsertRecord

62

, OnBeforeDeleteRecord

Client Side Page Events


PHP Generator for MySQL provides events fired either on the server or client sides.
Handlers for client side events are written on Javascript and executed by browsers
while server side event handlers are written on PHP and executed by a web server.
OnBeforePageLoad
OnAfterPageLoad

2014 SQL Maestro Group

64

64

64

PHP Generator for MySQL Help

OnInsertFormValidate
OnEditFormValidate

65

65

OnInsertFormEditorValueChanged
OnEditFormEditorValueChanged
OnInsertFormLoaded
OnEditFormLoaded

66

67

69

70

See also: Server Side Events

71

4.1.3.2.1 OnBeforePageLoad

This event occurs before page loading. It allows you to declare functions and global
variables. Use the event to include one or several files of a third-party library into the
generated pages.
Example
To get the details of the first master record expanded on opening of a certain page of
the generated application, define the expandFirstDetail function within the
OnBeforePageLoad event handler as follows:
function expandFirstDetail() {
if
($('table.pgui-grid').data('grid-class')){
var grid = $('table.pgui-grid').data('grid-class');
var $row =
$('table.pgui-grid tr.pg-row').first();
grid.expandDetails($row);
return true;
}
else {
setTimeout(expandFirstDetail, 100);
}
}

This function then should be called within the OnAfterPageLoad

64

event handler.

To see this example in action, visit the Players page of our demo application.
4.1.3.2.2 OnAfterPageLoad

This event occurs after page has been fully rendered. It does not get triggered until all
assets such as images have been completely received and DOM hierarchy has been fully
constructed.
Example 1:
To get details of the first record expanded on the webpage opening, specify Javascript
code as follows:
function expandFirstDetail() {
if ($('table.pgui-grid').data('grid-class')) {
var grid = $('table.pgui-grid').data('grid-class');
var $row =
$('table.pgui-grid tr.pg-row').first();
grid.expandDetails($row);
return true;
}
else {

2014 SQL Maestro Group

Customizing webpages

65

setTimeout(expandFirstDetail, 100);
}
}
expandFirstDetail();

It is also possible to specify the function above within the OnBeforePageLoad 64 event
handler. In this case the OnAfterPageload event handler should contain only the function
call:
expandFirstDetail();
4.1.3.2.3 OnInsertFormValidate

This event occurs before submitting of an insert form. It allows you to detect errors on
the client side before the form is submitted to the server to avoid the round trip of
information necessary for server-side validation.
Signature:
function

OnInsertFormValidate

(fieldValues,

errorInfo)

Parameters:
fieldValues

An associative array of values containing user input.

errorInfo

The object that provides interface (the SetMessage method) to


set a validation error message.

Example 1:
The code below demonstrates the verification of the percent number on the record
inserting.
if (fieldValues['percents'] < 0 || fieldValues['percents'] > 100)
{
errorInfo.SetMessage('Percent value should be between 0 and 100.');
return false;
}

Example 2:
The following code is used in the NBA demo project to ensure that home and away
teams are different for an inserted game:
if
{

(fieldValues['home_team_id']

==

fieldValues['away_team_id'])

errorInfo.SetMessage('"Home" and "Away" must be different');


return false;
}

See also: OnEditFormValidate

65

4.1.3.2.4 OnEditFormValidate

This event occurs before submitting an edit form. It allows you to detect errors on the
client before the form is submitted to the server to avoid the round trip of information
necessary for server-side validation.
Signature:
function

OnEditFormValidate

2014 SQL Maestro Group

(fieldValues,

errorInfo)

66

PHP Generator for MySQL Help

Parameters:
fieldValues

An associative array of values containing the user


input.

errorInfo

An object that provides interface (the SetMessage


method) to set a validation error message.

Example 1:
To validate the 'percents' value and show a warning message in case of erroneous input,
use the following code:
if (fieldValues['percents'] < 0 || fieldValues['percents'] > 100)
{
errorInfo.SetMessage('Percent value should be between 0 and 100.');
return false;
}

Example 2:
The following code is used in the NBA demo project to ensure that home and away
teams are different for an edited game:
if
{

(fieldValues['home_team_id']

==

fieldValues['away_team_id'])

errorInfo.SetMessage('"Home" and "Away" must be different');


return false;
}

See also: OnInsertFormValidate

65

4.1.3.2.5 OnInsertFormEditorValueChanged

This event occurs on changing a value in the Insert form.


Signature:
function

OnInsertFormEditorValueChanged

(sender,

editors)

Parameters:
sender

A control whose value has been changed.

editors

An associative array of form controls.

Example 1:
The code below allows you to select a college only for players from U.S. (see this in
action). See how it looks on the webpage at the screen below.
if
{

(sender.getFieldName()

==

'country_id')

editors['college_id'].enabled(sender.getValue()
if (sender.getValue() != 1)
editors['college_id'].setValue(null);

==

1);

2014 SQL Maestro Group

Customizing webpages

67

Example 2:
Another example from the insert and edit forms of the Players page (see this in action).
This piece of code allows you to select player number only if a player's team is already
selected (in other words, players who do not belong to a team cannot have numbers).
if
{

(sender.getFieldName()

==

'current_team_id')

if (sender.getValue() == '')
{
editors['current_number'].setValue('');
editors['current_number'].enabled(false);
}
else
{
editors['current_number'].enabled(true);
}
}

See also: OnEditFormEditorValueChanged

67

4.1.3.2.6 OnEditFormEditorValueChanged

This event occurs on changing a value in the Edit form.


Signature:
function

OnEditFormEditorValueChanged(sender,

Parameters:
2014 SQL Maestro Group

editor)

68

PHP Generator for MySQL Help

sender

A control whose value has been changed.

editors

An associative array of form controls.

Example 1:
The code below allows you to select a college only for players from U.S. (see this in
action). See how it looks on the webpage at the screen below.
if
{

(sender.getFieldName()

==

'country_id')

editors['college_id'].enabled(sender.getValue()
if (sender.getValue() != 1)
editors['college_id'].setValue(null);

==

1);

Example 2:
Another example from the insert and edit forms of the Players page (see this in action).
This piece of code allows you to select player number only if a player's team is already
selected (in other words, players who do not belong to a team cannot have numbers).
if
{

(sender.getFieldName()

==

'current_team_id')

if (sender.getValue() == '')
{
editors['current_number'].setValue('');
editors['current_number'].enabled(false);
}
else
{
editors['current_number'].enabled(true);
}
}

2014 SQL Maestro Group

Customizing webpages

See also: OnInsertFormEditorValueChanged

69

66

4.1.3.2.7 OnInsertFormLoaded

This event occurs after an Insert form is loaded.


Signature:
function

OnInsertFormLoaded(editor)

Parameters:
editors

An associative array of form controls.

Example:
This piece of code targets two things:
1) Player number is cleared and the appropriate control becomes disabled for players
that do not belong to a team.
2) Player's college is cleared and the appropriate control becomes disabled if player's
country is not USA (country code == 1).
editors['college_id'].enabled(editors['country_id'].getValue()
if (editors['country_id'].getValue() != 1)
editors['college_id'].setValue(null);

if
{

(editors['current_team_id'].getValue()

==

editors['current_number'].setValue('');
editors['current_number'].enabled(false);
}
else
{
editors['current_number'].enabled(true);
}

2014 SQL Maestro Group

'')

==

1);

70

PHP Generator for MySQL Help

See also: OnEditFormLoaded

70

4.1.3.2.8 OnEditFormLoaded

This event occurs after the Edit form is loaded.


Signature:
function OnEditFormLoaded(editor)

Parameters:
editors

An associative array of form controls.

Example:
This piece of code targets two things:
1) Player number is cleared and the appropriate control becomes disabled for players
that do not belong to a team.
2) Player's college is cleared and the appropriate control becomes disabled if player's
country is not USA (country code == 1).
editors['college_id'].enabled(editors['country_id'].getValue()
if (editors['country_id'].getValue() != 1)
editors['college_id'].setValue(null);

if
{

(editors['current_team_id'].getValue()

==

==

1);

'')

editors['current_number'].setValue('');
editors['current_number'].enabled(false);
}
else

2014 SQL Maestro Group

Customizing webpages

71

{
editors['current_number'].enabled(true);
}

See also: OnInsertFormLoaded


4.1.3.3

69

Server Side Page Events


PHP Generator for MySQL provides events fired either on the server or client sides.
Handlers for client side events are written on Javascript and executed by browsers
while server side event handlers are written on PHP and executed by a web server.
OnBeforePageExecute

72

OnCustomRenderColumn

72

OnCustomRenderPrintColumn

75

OnCustomRenderExportColumn
OnCustomHTMLHeader

76

OnExtendedCustomDrawRow
OnCustomRenderTotals

78

OnGetCustomTemplate

79

OnCustomDrawRow

75

76

83

Using variables
PHP Generator for MySQL supports some environment variables (such as
CURRENT_USER_ID, CURRENT_USER_NAME, UNIQUE_ID) in events. To obtain a complete
list of supported variables, turn ON the "Show environment variables" option in the
Project options dialog, re-generate the code and then open any of produced web pages
in the browser. The following example demonstrates how to use variables within the
OnBeforeInsertRecord 86 event handler.
2014 SQL Maestro Group

72

PHP Generator for MySQL Help

$rowData['ip_address']
=
$this->GetEnvVar('REMOTE_ADDR');
$userName
=
$this->GetEnvVar('CURRENT_USER_NAME');
if ($userName != 'admin')
$rowData['changed_by'] = $userName;

See also: Client Side Events

63

4.1.3.3.1 OnBeforePageExecute

This event handler contains PHP code to be included at the begin of generated pages.
This code is executed only once and intended to create global objects, declare
functions, include third-party libraries, and so on.
Example:
Suppose we decided to implement a syntax highlighting using the GeSHi library
somewhere in the generated application. To implement such a feature, we need (among
other things) to include the main library file into the generated scripts, so the event
handler should be specified as follows:
include_once

'../geshi/geshi.php';

4.1.3.3.2 OnCustomRenderColumn

This event occurs before column rendering and allows you to completely replace the cell
content. It is an extremely useful event for conditional rendering or embedding thirdparty components to extend standard functionality.
Signature:
function

OnCustomRenderColumn

( $fieldName, $fieldData, $rowData, &$customText, &$handled)

Parameters:
$fieldName

The field name for the currently processed cell.

$fieldData

The data of currently processed cell.

$rowData

The associative array of values that corresponds to


the currently processed row.

$customText

A string to replace the original cell content.

$handled

A parameter to indicate whether the event handler


takes effect. Set $handled to true to apply the new
content.

Example 1:
Suppose a table 'employee' has a column storing data about the
employee's sex in that way that '1' corresponds to male and '2' to female.
Our goal is to represent the employees sex as 'M' and 'F' for men and
women
accordingly.
To
do
so,
you
could
specify
the
OnCustomRenderColumn event handler as follows:
if ($fieldName == 'sex') {
$customText = $rowData['sex'] == 1 ? 'M' : 'F';
$handled = true;
}

2014 SQL Maestro Group

Customizing webpages

73

Example 2:
The code below is used in our demo project to show the number of overtime periods
played in the game.
if ($fieldName == 'overtime_count')
{
if ($fieldData > 0)
$customText = $fieldData . ' OT';
else
$customText = '-';
$handled = true;
}

The screenshot demonstrates the result of this event fired on the Games webpage.

Example 3:
The code below is used in our demo project to add flag images to the "Country" column.
if
{

($fieldName

==

'current_team_id')

if (!isset($fieldData))
{
$customText = 'Free agent';
$handled = true;
}
}
elseif ($fieldName == 'country_id')
{
$countriesPics = array (
1 => 'us',
2 => 'fr',
3 => 'br',
4 => 'it',
6 => 'sp',
8 => 'ar',
11 => 'li',
15 => 'ru',
18 => 'gr',
20 => 'ge'
);
$customText =
'<div style="width: 80px; text-align: left;">' .
'<img src="countries/'.$countriesPics[$rowData['country_id']].'.png">' .
'&nbsp;' . $fieldData .
'</div>';
$handled = true;
}

2014 SQL Maestro Group

74

PHP Generator for MySQL Help

Example 4
This example demonstrates the applying of the syntax highlighting provided by the Geshi
library. We use this library to highlight SQL syntax in strings stored in the 'Body' column.
if ($fieldName == 'Body')
{
$source = $rowData['Body'];
$language = 'sql';
$formatted_sql = SqlFormatter::format($source, false);
$geshi = new GeSHi($formatted_sql, $language);
$customText =
'<div align="left">'.$geshi->parse_code().'</div>';
$handled = true;
}

2014 SQL Maestro Group

Customizing webpages

See also: OnCustomRenderPrintColumn

75

, OnCustomRenderExportColumn

75

75

4.1.3.3.3 OnCustomRenderPrintColumn

This event occurs before column rendering on the print page and allows you to replace
cell content. It is an extremely useful for conditional rendering or embedding third-party
components to extend standard functionality.
Signature:
function

( $fieldName, $fieldData, $rowData, &$customText, &$handled)

OnCustomRenderPrintColumn

Parameters:
$fieldName

The field name of currently processed cell.

$fieldData

The data of currently processed cell.

$rowData

The associative array of values that corresponds to


the currently processed row.

$customText

A string to replace the original cell content.

$handled

A parameter to indicate whether the event handler


executed. Set $handled to true in the event handler to
apply new content.

See also: OnCustomRenderColumn

72

, OnCustomRenderExportColumn

75

4.1.3.3.4 OnCustomRenderExportColumn

This event occurs before column rendering into Word, Excel, etc. and allows you to
replace cell content. It is an extremely useful event for conditional rendering.
Signature:
function

OnCustomRenderExportColumn

($fieldName, $fieldData, $rowData, &$customText, &$handled)

Parameters:
$fieldName

The field name of currently processed cell.

$fieldData

The data of currently processed cell.

2014 SQL Maestro Group

76

PHP Generator for MySQL Help

$rowData

The associative array of values that corresponds to the


currently processed row.

$customText

A string to replace the original cell content.

$handled

A parameter to indicate whether the event handler


executed. Set $handled to true in the event handler to
apply new content.

See also: OnCustomRenderColumn

72

, OnCustomRenderPrintColumn

75

4.1.3.3.5 OnCustomHTMLHeader

This event occurs when the head section of the page is generating. Use it to provide
additional information for the HEAD section of the page (such as keywords, author, or
description).
Signature:
function

OnCustomHTMLHeader

($page,

&$customHtmlHeaderText)

Parameters:
$page

An instance of the Page class declared in


components/page.php

$customHtmlHeader
Text

A string to place into the head section

Example:
The following code demonstrates how to use this event to add metadata to the
generated webpage.
$customHtmlHeaderText

'<meta

name="copyright"

content="SQL

Maestro

Group"/>';

4.1.3.3.6 OnExtendedCustomDrawRow

This event occurs when rendering a grid row and allows you to change the row and/or
cell styles directly. It is an extremely useful event for conditional formatting such as
changing font color, font styles, row background color, cell background color, etc. The
specified styles are applied to <tr> and <td> tags accordingly.
Signature:
function

OnExtendedCustomDrawRow

($rowData, &$rowCellStyles , &$rowStyles )

Parameters:
$rowData

The associative array of values that corresponds to


the currently processed row.

$rowCellStyles

The associative array of styles. Each field name is


associated with its style string.

$rowStyles

The string to modify styles of a whole row.

This event (as well as OnCustomDrawRow 83 ) is used for conditional formatting. The
only difference between these two events is that OnCustomDrawRow has a more
understandable parameter list while OnExtendedCustomDrawRow provides more flexible
abilities.

2014 SQL Maestro Group

Customizing webpages

77

Example 1:
The code below is used in our online demo to display the winning team score in red and
the losing team score in black; moreover, both scores should be in bold and displayed by
a 16pt font.
$rowCellStyles['home_team_score'] = 'font-size: 16pt;font-weight:
$rowCellStyles['away_team_score'] = 'font-size: 16pt;font-weight:
if ($rowData['home_team_score'] > $rowData['away_team_score'])
$rowCellStyles['home_team_score'] .= 'color: #F65317;';
else
$rowCellStyles['away_team_score'] .= 'color: #000000;';

bold;';
bold;';

The screenshot demonstrates the result of the event fired on the Games webpage.

Example 2
The code below is used in our online demo to highlight fields representing player's height
depending on the value.
$height = $rowData['height'];
$color = '#fffff';
if ($height > 200)
$color = '#f79646';
elseif ($height > 185)
$color = '#fac090';
elseif ($height > 170)
$color = '#fde9d9';
$rowCellStyles['height'] = "background-color:

2014 SQL Maestro Group

$color;

font-weight:

bold;";

78

PHP Generator for MySQL Help

4.1.3.3.7 OnCustomRenderTotals

This event occurs before total values rendering and allows you to replace the default
total footer content. To use it, enable the grid footer in the View properties 31 of the
corresponding column.

Signature:
function

OnCustomRenderTotals

($totalValue,

$aggregate,

$columnName,

&$customText,

&$handled)

Parameters:
$totalValue

The value of currently processed total.

$aggregate

The string representation of total aggregate ('AVG',


'SUM', 'MIN', 'MAX', 'COUNT').

$columnName

The column name of currently processed total.

$customText

A string to replace the total cell content.

$handled

A parameter to indicate whether the event handler


executed. Set $handled to true in the event handler to
apply new content.

Example 1:
The code below changes the caption of the 'amount' column footer and gives it strong
importance.
if ($columnName == 'amount')
{
$customText = '<strong>Total: $' . $totalValue . '</strong>';
$handled = true;
}

This picture demonstrates the difference between a webpage generated with default
footer and a webpage with the OnCuStomRenderTotals event specified in this way:

2014 SQL Maestro Group

Customizing webpages

79

Example 2:
The code below is used in our online demo on the 'Teams' page to display the year of
foundation of the oldest team on the page in more convenient form.
if ($columnName == 'year_founded') {
$customText = 'MIN: ' . intval(str_replace(',', '', $totalValue));
$handled = true;
}

4.1.3.3.8 OnGetCustomTemplate

This event occurs on opening a custom template and allows to use a custom template
instead of the default one.
Signature:
function

OnCustomRenderColumn

($part,

$mode,

&$result,

&$params)

Parameters:
$part

The part of the page to be affected by the template.

$mode

The current state of the webpage the template to be


used.

$result

The path to the file to be used as template according


to the components/templates/custom_templates
folder.

$params

An associative array of additional parameters you


want to assign to the template.

PHP Generator creates a set of templates written on Smarty 2.0 to be used by the
prepared application in the certain situations. The basic principles of custom template
usage are shown in this article. To change any webpage look, you need to:

2014 SQL Maestro Group

80

PHP Generator for MySQL Help

specify a new template to be used for this webpage;


set PHP Generator to use this template for the selected webpage.
The simplest way to create a new template is to modify an existing one (it's much easier
than create a new template "from scratch"). Use the table below to select the template
corresponding to the necessary state of page and page part. Custom template files
should be uploaded to the 'components/templates/custom_template' directory. This
folder should be created by the user of PHP Generator and its content is not changing
during the further PHP Generator sessions.
State of the
webpage

Page Part

Default template

Parameters

navigation bar

page_list.tpl

PagePart::PageList
Any PageMode

webpage layout

common/layout.tpl

PagePart::Layout
Any PageMode

table grid

list/grid.tpl

PagePart::Grid
PageMode::ViewAll

single row

list/single_row.tpl

PagePart::GridRow
PageMode::ViewAll

View form

view/grid.tpl

PagePart::RecordCard
PageMode::View

Edit form

edit/grid.tpl

PagePart::VerticalGrid
PageMode::Edit

Insert form

insert/grid.tpl

PagePart::VerticalGrid
PageMode::Insert

View modal dialog

view/record_card_view.tpl PagePart::VerticalGrid

All Pages

List page

PageMode::ModalView
Edit modal dialog

edit/vertical_grid.tpl

PagePart::VerticalGrid
PageMode::ModalEdit

Insert modal dialog

insert/vertical_grid.tpl

PagePart::Grid
PageMode::
ModalInsert

To instruct PHP Generator to use a customized template file for a certain webpage,
specify the following code in the page's OnGetCustomTemplate event handler (of course
you should replace YourPart and YourMode to the appropriate values from the table
above).
2014 SQL Maestro Group

Customizing webpages

81

if ($part == YourPart && $mode == YourMode) {


$result = 'your_template_file.tpl';
}

Example 1:
Suppose we need to use components/templates/custom_templates/staff_edit.tpl file as
a template for the edit form of a webpage.
if ($part == PagePart::VerticalGrid && $mode == PageMode::Edit) {
$result = 'staff_edit.tpl';
}

Now we can compare the result webpages without using this event and with the enabled
one:

Example 2:
One event can include several templates to be applied to different state and page parts
of the selected webpage. The following code is used in our online demo:
if ($part == PagePart::Grid && $mode == PageMode::ViewAll)

2014 SQL Maestro Group

82

PHP Generator for MySQL Help

$result =
if ($part ==
$result =
if ($part ==
$result =

'games_grid.tpl';
PagePart::VerticalGrid && $mode == PageMode::Edit)
'games_edit.tpl';
PagePart::RecordCard && $mode == PageMode::View)
'games_view.tpl';

Example 3
This example shows how to fill a SELECT input with names of all MySQL databases
available at the server.
1. Specify the OnGetCustomTemplate event handler as follows:
// set the template file
if ($part == PagePart::Grid && $mode == PageMode::ViewAll) {
$result = 'custom_grid.tpl';
//

get the list of available databases


$queryResult = array();
$this->GetConnection()->ExecQueryToArray('SHOW

DATABASES',

//

fill a one-dimensional array with database names


$databaseNames = array();
foreach($queryResult as $row)
$databaseNames[] = $row[0];

//

assign the parameter in the template


$params['databaseNames'] = $databaseNames;

$queryResult);

2. Add the following code to the template file:


<select
name="database">
{foreach from=$databaseNames item=database}
<option value="{$database}">{$database}</option>
{/foreach}
</select>

The screen below demonstrates the result output.

Example 4
This example shows the use of the superglobal $_GET array values in a custom template.
1. Specify the OnGetCustomTemplate event handler as follows:
2014 SQL Maestro Group

Customizing webpages

83

if ($part == PagePart::Grid && $mode == PageMode::ViewAll) {


$result = 'custom_grid.tpl';
// check if the parameter custom_var available
if (GetApplication()->IsGETValueSet('custom_var'))
// found
$params['custom_var'] = GetApplication()->GetGETValue('custom_var');
else
// not found. Assign a default value.
$params['custom_var'] = '5 (default)';
}

2. Add the following code to the template file:


<div>
<h4>I am a custom template with a custom variable $custom_var. Its value
{if !isset($custom_var)}
still undefined
{else}
= {$custom_var}
{/if}.
</h4>
</div>
4.1.3.3.9 OnCustomDrawRow

This event occurs on rendering a grid row. It is an extremely useful event for conditional
formatting such as changing font color, font styles, row background color, cell
background color, etc. This event (as well as the OnExtendedCustomDrawRow 76 one) is
used for conditional formatting. The only difference between these two events is that
OnCustomDrawRow
has
a
more
understandable
parameter
list
while
OnExtendedCustomDrawRow provides more flexible abilities.
Signature:
function

OnCustomDrawRow

($rowData,

&$cellFontColor,

&$cellFontSize,

&$cellBgColor,

Parameters:
$rowData

The associative array of values that corresponds to


the currently processed row.

$cellFontColor

The parameter allows to set a font color for selected


fields.

$cellFontSize

The parameter defines a font size of selected data.

$cellBgColor

The parameter allows to set a background color of


fields.

$cellItalicAttr

Set the parameter to true to represent text in cursive


font.

$cellBoldAttr

Set the parameter to true to use bold font.

NB. Array keys should contain the real column names in the data source (table, view, or
query). Don't use the column's caption instead!
Example 1:
Suppose we need to
2014 SQL Maestro Group

create a webpage with list of customers with addresses

&$cellItalicAt

84

PHP Generator for MySQL Help

represented in cursive. This column in the data source is named 'address_id' and the
column's caption is "Address".

To define the font attribute, the use the code as follows:


$cellItalicAttr['address_id']

true;

Example 2:
Please find below an example of the conditional row formatting from our online demo. We
need to display winning team score in red and losing team score in black; moreover, both
scores should be in bold and displayed by a 16pt font.
$cellFontSize['home_team_score']
$cellBoldAttr['home_team_score']

=
=

'16pt';
true;

$cellFontSize['away_team_score']
$cellBoldAttr['away_team_score']

=
=

'16pt';
true;

if

($rowData['home_team_score'] > $rowData['away_team_score'])


$cellFontColor['home_team_score'] = '#F65317';
else
$cellFontColor['away_team_score'] = '#000000';
4.1.3.3.10 OnAfterUpdateRecord

This event occurs when the Update command is executed, and after the actual update.
This event is often used to execute actions after update operation.
Signature:
function

OnAfterUpdateRecord

($page,

&$rowData,

$tableName)

Parameters:
$page

An instance of the Page class declared in


components/page.php.

$rowData

The associative array of values that corresponds to


the currently processed row.

$tableName

The name of processed table.

See also: OnAfterDeleteRecord 85 , OnAfterInsertRecord


OnBeforeUpdateRecord (global event) 62 .

85

, OnBeforeUpdateRecord

85

2014 SQL Maestro Group

Customizing webpages

85

4.1.3.3.11 OnAfterDeleteRecord

This event occurs when the Delete command is executed, and after the actual deletion.
This event is often used to execute actions after delete operation.
Signature:
function

OnAfterDeleteRecord

($page,

&$rowData,

$tableName)

Parameters:
$page

An instance of the Page class declared in


components/page.php.

$rowData

The associative array of values that corresponds to


the currently processed row.

$tableName

The name of processed table.

See also: OnAfterUpdateRecord 84 , OnAfterInsertRecord


OnBeforeDeleteRecord (global event) 63 .

85

, OnBeforeDeleteRecord

86

4.1.3.3.12 OnAfterInsertRecord

This event occurs when the Insert command is executed, and after the actual insertion.
This event is often used to execute actions after insert operation.
Signature:
function

OnAfterInsertRecord

($page,

&$rowData,

$tableName)

Parameters:
$page

An instance of the Page class declared in


components/page.php.

$rowData

The associative array of values that corresponds to


the currently processed row.

$tableName

The name of processed table.

See also: OnAfterUpdateRecord 84 , OnAfterDeleteRecord


OnBeforeInsertRecord (global event) 62 .

85

, OnBeforeInsertRecord

86

4.1.3.3.13 OnBeforeUpdateRecord

This event occurs when the Update command is executed against a specific table, but
before the actual update. It is often used to cancel the update operation.
Signature:
function

OnBeforeUpdateRecord

($page,

&$rowData,

&$cancel,

&$message,

Parameters:
$page

An instance of the Page class declared in


components/page.php.

$rowData

The associative array of values that corresponds to


the currently processed row.

$cancel

The value indicating whether the operation should be


canceled.

2014 SQL Maestro Group

$tableName)

86

PHP Generator for MySQL Help

$message

The message string that is displayed after the


operation is completed (or canceled).

$tableName

The name of processed table.

Example:
The code below unconditionally disables the modification of records.
$cancel = true;
$message = 'Updating is disabled.';

See also: OnBeforeDeleteRecord 86 , OnBeforeInsertRecord


OnBeforeUpdateRecord (global event) 62 .

86

, OnAfterUpdateRecord

84

4.1.3.3.14 OnBeforeDeleteRecord

This event occurs when the Delete command is executed against a specific table, but
before the actual deletion. It is often used to cancel the delete operation.
Signature:
function

OnBeforeDeleteRecord

($page,

&$rowData,

&$cancel,

&$message,

$tableName)

Parameters:
$page

An instance of the Page class declared in


components/page.php.

$rowData

The associative array of values that corresponds to


the currently processed row.

$cancel

The value indicating whether the operation should be


canceled.

$message

The message string that is displayed after the


operation is completed (or canceled).

$tableName

The name of processed table.

Example:
The code below unconditionally disables the deletion of records.
$cancel = true;
$message = 'Deleting is disabled.';

See also: OnBeforeUpdateRecord 85 , OnBeforeInsertRecord


OnBeforeDeleteRecord (global event) 63 .

86

, OnAfterDeleteRecord

85

4.1.3.3.15 OnBeforeInsertRecord

This event occurs when the Insert command is executed against a specific table, but
before the actual insertion. It is often used to cancel the insert operation.
Signature:
function

OnBeforeInsertRecord

($page,

&$rowData,

&$cancel,

&$message,

$tableName)

Parameters:
$page

An instance of the Page class declared in


components/page.php.
2014 SQL Maestro Group

Customizing webpages

$rowData

The associative array of values that corresponds to


the currently processed row.

$cancel

The value indicating whether the operation should be


canceled.

$message

The message string that is displayed after the


operation is completed (or canceled).

$tableName

The name of processed table.

87

Example 1:
The code below unconditionally disables the insertion of new records.
$cancel = true;
$message = 'Inserting is disabled.';

Example 2:
$rowData['ip_address']
=
$this->GetEnvVar('REMOTE_ADDR');
$userName
=
$this->GetEnvVar('CURRENT_USER_NAME');
if ($userName != 'admin')
$rowData['changed_by'] = $userName;

See also: OnBeforeUpdateRecord 85 , OnBeforeDeleteRecord


OnBeforeInsertRecord (global event) 62 .

4.1.4

86

, OnAfterInsertRecord

85

Filter
To reduce the number of records available at the page, specify the Filter condition. This
condition corresponds to the WHERE clause of the query returned page data (you must
not add the WHERE keyword to beginning of the condition).
Example 1
There is a table with test questions of a Web programming course. To display only
questions
of
the 'Beginner'
level
(level_id
=
2)
concerning
to
PHP
(statement_language_id = 1), set the filter condition as follows:

Example 2
You can use subqueries in the filter expression. For example, to display the list of
2014 SQL Maestro Group

88

PHP Generator for MySQL Help

channels that hosted even if a single game, specify the Filter condition as follows:
(channel.id > 0) AND channel.id IN
(
SELECT game.channel_id
FROM game
)

4.1.5

Page Properties
The Page Properties window allows you to define the general properties of the generated
page. To invoke the window, use the corresponding button of Page Editor 26 .
Common
Specify here the basic HTML elements such as Caption of the generated HTML page, File
name (if the file name extension is not specified, it will be the same as at the application
output options 126 ). Short Caption is a text of the link representing the page at Navbar.
To add a text to be displayed at the top of the page, use the Page Header field or open
the Page Header window with the ellipsis button (for details see the screenshot below).

Default sort order


To set the default sort order of the generated page data, check the Default ordering
box, specify the name of the column the data to be sorted according with and select
the sort order.
Fixed width of the grid
To set a fixed width of the grid, check the Grid fixed width, specify the Width, and
select the Units.
Units
em
px
in
cm
mm

Meaning
The 'font-size' of the relevant font.
(pixels) Relative to the viewing device.
(inches) 1 inch is equal to 2.54 centimeters.
Centimeters
Millimeters

2014 SQL Maestro Group

Customizing webpages

pt
pc

89

(points) The points used by CSS 2.1 are equal to 1/72nd of an inch.
(picas) 1 pica is equal to 12 points.

Creating RSS feeds


The Use RSS 91 options group allows you to create an RSS feed based on the current
table.
Opening search page at first
For tables storing a lot of data it's reasonable to allow users to work only with a
necessary piece of data. For this purpose, check the Open search page at first box and
the generated page will be opened with a search page.
The other properties are set in accordance with the project options 121 . To change the
properties, check off the Use default options box and enter the new value in the
corresponding field.

4.1.6

Data Partitioning
The Data Partitioning wizard allows you to create a custom pagination i.e. split the
records on the generated page by a specified criteria.
Select the type of data partitioning on the first wizard step:

Range partitioning
Selects a partition by determining if the partitioning expression value is inside a
certain range.

List partitioning
A partition is assigned a list of values. If the partitioning expression value has one
of these values, the partition is chosen. For example, all rows where the column
'Country' is either Iceland, Norway, Sweden, Finland or Denmark could build a
partition for the 'Nordic countries'.

Custom partitioning
Create your own partitioning with fill partitions and build conditions functions.

To disable data partitioning, select None.

Example 1 (Range partitioning)


There is a table storing information about films such as title, release year, and length.
See definition here
CREATE TABLE film (
film_id
title
release_year
length
/* Keys */
PRIMARY KEY (film_id)
);

2014 SQL Maestro Group

integer NOT NULL,


varchar(255) NOT NULL,
integer,
integer UNSIGNED,

90

PHP Generator for MySQL Help

To create a pagination by the film length, select Range partitioning at the first wizard
step, choose 'length' as partition expression and set the partitioning ranges as follows:

Here you can see the result PHP script:

Example 2 (Custom partitioning)


Assume that a table 'customer' contains the 'last_name' column. Our goal is to group
customers by the first letter of their last name as displayed below.

2014 SQL Maestro Group

Customizing webpages

91

To get around such a situation, select Custom partitioning and define functions as
follows:
function GetPartitions($partitions)
{
$tmp = array();
$this->GetConnection()->ExecQueryToArray("
SELECT DISTINCT
left(c.last_name, 1) as first_letter
FROM customer c
ORDER BY first_letter", $tmp
);
foreach($tmp as $letter) {
$partitions[$letter['first_letter']] = $letter['first_letter'];
}
}
function GetPartitionCondition($partitionKey, &$condition)
{
$condition = "left(last_name, 1) = '$partitionKey'";
}

4.1.7

RSS
With PHP Generator for MySQL you can create full-fledged RSS feeds based on MySQL
tables. To create an RSS document, open the Page Properties dialog and complete the

2014 SQL Maestro Group

92

PHP Generator for MySQL Help

Use RSS options group.


Check the Use RSS box first and specify the following options:
Channel title
Defines the title of the channel.
Channel link
Defines the hyperlink to the channel.
Channel description
Describes the channel.
Item title template 51
Defines the title of the item.
Item link template 51
Defines the hyperlink to the item.
Item description template
Describes the item.

51

Item publication date field


This field is optional. Defines the last publication date for the content of the feed.
For more details see the RSS specification.
The screen below provides you with a simple example.

2014 SQL Maestro Group

Customizing webpages

2014 SQL Maestro Group

93

94

4.2

PHP Generator for MySQL Help

Project Options
PHP Generator for MySQL allows you to specify default settings to be applied to each
generated webpage. By default, most of these options have the same values as the
application options 121 . To open this dialog window, follow the Setup project options to
configure default page settings link at the Customizing webpages 25 wizard step
All settings are grouped into several tabs:
Page
The Page tab allows to modify the appearance of webpages, specify the script abilities
such as data formats available for data export, data view mode, data edit mode, data
insert mode and also delete, search and filter abilities. By default these settings are set
in accordance with the Application options 121 .
Display formats
These tab fields allow to adjust the display data formats in the way you need. By
default these settings are set in accordance with the Application options 121 .
Advanced options
The tab allows you to specify whether PHP errors and warnings, environment variables
and executed queries will be shown, and to disable magic quotes_runtime option.
Events
You can also specify events 60 to be executed on all generated page after successful
login, before update/insert/delete operations.

2014 SQL Maestro Group

Customizing webpages

2014 SQL Maestro Group

95

96

PHP Generator for MySQL Help

Webpages appearance
PHP Generator for MySQL allows you to setup the appearance of created webpages in
several ways:
Built-in color schemes 99
The simplest way to adjust the look and feel of the result application is to select
one of color schemes the software comes with.

A sample webpage generated using different color schemes.


Custom color scheme 99
This allows you to provide the application with a specific look and feel defining the
colors and font settings.

2014 SQL Maestro Group

Webpages appearance

97

A sample webpage generated with custom color scheme.


Header and Footer 100
These are fragments of HTML code that will be included into all the generated
pages. They can be customized within the appropriate window.

A sample webpage with specified header.


Custom CSS 101
It is also possible to define a custom style sheet to be applied after all pre-defined
CSS rules. This can be useful to define such things as size of controls, text
alignments, background images, and more.

2014 SQL Maestro Group

98

PHP Generator for MySQL Help

Events 59
Events are pieces of code that are run when an action is taken by the user. Such
events
as
OnBeforePageExecute 72 ,
OnCustomRenderColumn 72 ,
and
OnCustomDrawRow 83 can be used to change the webpage appearance. Please
find some examples of using these and other events in our demo application and in
the Resources section at the product home page.
Using templates 103
While all the previously described methods allow you to define colors, fonts, text
alignments, and other display attributes of generated webpages, this one helps
you to redesign the webpages entirely i.e. define what controls are displayed on a
specific form, where they are displayed, and what they display.

2014 SQL Maestro Group

Webpages appearance

5.1

99

Color schemes
The color scheme of created application contains the information on basic style
definitions for all key HTML components: fonts, colors, backgrounds, borders, and
others. PHP Generator for MySQL comes with a number of built-in color schemes. To
use one of them, select the appropriate item from the "Color scheme" drop-down list.
To change default scheme settings according to your needs, click the Customize color
scheme button and modify the necessary variables within the Grid CSS window. To learn
more about the LESS syntax used in this window, please refer to the LESS manual.

The Preview window displays current appearance settings applied to a sample webpage.

2014 SQL Maestro Group

100

5.2

PHP Generator for MySQL Help

Header and Footer


To add an HTML markup to be displayed at the top and at the bottom of each page of
the generated web application, enter the appropriate code in the Header and Footer
text boxes accordingly.

Example: To add the header like one on the screen above, paste the following text in
the Header edit box:
<table width="600px" height="110px">
<tr>
<td>
<img src="images/mysql_logo.png" /></td>
<td>
<h2>MySQL Schema Browser</h2>
</td>
<td>
<div>
Created by <a
href="http://www.sqlmaestro.com/products/mysql/
phpgenerator/">PHP Generator for MySQL.</a>
<br>Want to learn more? <br>
<a
href="http://www.sqlmaestro.com/products/mysql/phpgenerator/
download/">Download the demo project!</a></div>
</td>
</tr>
</table>

2014 SQL Maestro Group

Webpages appearance

5.3

101

Custom CSS
The ability to use custom CSS allows you to set up such parameters of web pages as
size of controls, text alignment, and more. To define a custom style sheet that will be
applied after all the pre-defined rules, click the "Edit additional CSS" button and enter
the rules you need manually or load them from a .css file.
To determine a selector to apply the styles for, use any available inspect HTML tools
such as default Firefox developer tools, Firebug, Chrome developer tools, Internet
Explorer developer tools, and so on. Among other things these tools allows you to view
the current element's attributes and applied styles and experiment with new ones.
Example 1
Suppose we need to set the width of the Address Id drop-down list to 300 pixels.
First of all we need to locate this control on the page (at the screen below we
used Firefox developers tools).

As we can see, the tag of the control is select and its id is address_id_edit. So to
specify the necessary width of the Addredd Id control, we need to add the
following rule to the Custom CSS (the select#address_id_edit will also work, but it
is not necessary as each id attribute must have a unique value within a document
):
#address_id_edit {
width: 300px;
}
To change the width of all the drop-down lists in the application, add the following
lines:
select {
width: 300px;
}
Example 2
To change the text alignment of the control from the example 1, add the following
string:
#address_id_edit {
text-align: right;
}
Example 3
To add a background image to all generated webpages, add the following rule to
the custom CSS.
#content-block {
2014 SQL Maestro Group

102

PHP Generator for MySQL Help

background-image: url('path/to/background.jpg');
}

2014 SQL Maestro Group

Webpages appearance

5.4

103

Using templates
Applications created by PHP Generator for MySQL use Smarty, a typical representative
of the web template engines family. So in order to redesign a webpage, you need to
change the appropriate template. All templates used by the software are stored in the
components/templates subfolder of the output directory. Each folder in this catalog
contains template files to be used by the application in different cases: on editing,
printing, inserting, etc.
Using custom templates
To change the webpage appearance with custom templates, follow these steps:

Create a new template. Custom templates must be stored under the components/
templates/custom_templates folder which contents is not changing on re-generation
of the scripts. You must create this folder manually.

Instruct PHP Generator to use this template for the selected webpage with the
OnGetCustomTemplate event.

Customize the template according to your needs and preferences.

The detailed description of such customization is given in the appropriate article.


Another article learns how to add a chart component to a webpage using the way
described above. The demo application also shows some additional examples of using
custom templates.

2014 SQL Maestro Group

104

PHP Generator for MySQL Help

Changing existing templates


You can modify generated template files directly. The example of supplying of generated
pages with look and feel of an existing website illustrates this method in the appropriate
article. Since all the templates are rewritten each time you generate an application, you
have to add modified templates to the Excluded files 118 list to prevent them from
overwriting.

2014 SQL Maestro Group

Security settings

105

Security settings
Check the Enable security option to supply the generated application with a login page
to request user name and password when someone attempts to access your script. PHP
Generator for MySQL provides you with the following authorization types:
Hard-coded authorization 107
Select this option to incorporate the authorization procedure directly into the PHP
code of the generated application.
Table-based authorization 109
Select this option to authorize a user of the web application by a login/password
combination stored in a database table.
Database server authorization 111
Select this option to accomplish the authorization by MySQL server.

See also: User permissions

2014 SQL Maestro Group

112

, Record-level security

115

106

PHP Generator for MySQL Help

2014 SQL Maestro Group

Security settings

6.1

107

Hard-coded authorization
To set the hard-coded authorization, fill in the Administrator login and Administrator
password fields and add as many additional users as you need. Check the Enable guest
access option to allow an anonymous user to access the generated app without
completing the authentication procedure.
Note: To allow guest access, specify also the corresponding guest's permissions

112

Turn Enable MD5 password encryption 'ON' to store user passwords encrypted with the
MD5 algorithm.

To add an application user, open the Hard-coded authorization window with the Edit
additional users button and open the User editor by the corresponding button or the
corresponding link at the tab's popup menu.

2014 SQL Maestro Group

108

PHP Generator for MySQL Help

Enter the user name and password, and check the necessary options to grant the
corresponding permissions to the user.

To learn how to specify permissions of the created users, see the User permissions
section.

112

2014 SQL Maestro Group

Security settings

6.2

109

Table-based authorization
Setting a table-based authorization means to allow user access to the generated scripts
according to grants stored in a MySQL table. The user login information is stored in a
MySQL table too. The tables may be prepared earlier or created within PHP Generator.

If the table with login information exists,


specify it's name as Users table and the columns with user names and passwords to be
used for authentication as Login field and Password field and set the user ID field. To
use encrypted passwords, select the corresponding encryption algorithm in the Password
encryption field from the list of available algotithms (MD5, SHA1, PHPass algorithm,
SHA246, and Crypt) or enter the necessary hash algorithm to be used for the password
encryption.
If the table with login information does not exist,
click the Create new table... button to set the name of a table to be created and its
column names.

Now the table is ready to use. You can enter the login info using any available MySQL
management tool, such as MySQL Maestro.
The checked Enable guest access option allows users those names are not stored in the
2014 SQL Maestro Group

110

PHP Generator for MySQL Help

table to work with generated script.


By default all users of result application have SELECT, UPDATE, INSERT, and DELETE
permissions. You can restrict their permissions with the Permissions manager 112 .
To allow the record-level security

115

at the generated application, specify User ID.

2014 SQL Maestro Group

Security settings

6.3

111

Database server authorization


This kind of authorization forces you to create and manage users permissions with the
server facilities. To allow access without entering a password, you need have a guest
account on the server and specify the guest credentials at the corresponding fields.

2014 SQL Maestro Group

112

6.4

PHP Generator for MySQL Help

Permission manager
Permission manager allows you to restrict user access to the generated application. To
open the window, press the Manage permissions... button. This is not applicable for the
database server authorization, in that case the grants should be set with the server
facilities.

Hard-coded authorization
All the permission information is stored in the prepared script and, to modify user grants,
you need to repeat the generation process. Use the checkboxes at the Permissions tab
to grant ADMIN, SELECT, UPDATE, INSERT, and DELETE permissions to the generated
application to users specified at the Hard-coded authorization window 107 . The ADMIN
permission means that the user can accomplish all available operations and none
restrictions including record-level security are not applied for him. To set permission on a
specified table, use the Customize page level permission... button.

2014 SQL Maestro Group

Security settings

113

Table-based authorization
All the information about user permission may be stored in the prepared script (as in the
case above), but it is recommended to store the info in a MySQL table. You can use for
this purpose an existing table or create a new one. In case you store user permission in
a table, you can manage them via administration panel and need not to regenerate PHP
scripts. One thing you need to note is that at least one user must have the ADMIN
permission in order to the administration panel will be generated.

2014 SQL Maestro Group

114

PHP Generator for MySQL Help

Open the Storage tab of the Permission manager.


Specify the name of an existing table to be use to store user permission info and its
columns names or use create such table with the corresponding button.
Open the Permissions tab and set the user permissions to be applied to all pages of the
generated application.
If necessary, refine permissions for each users on each page of the application within
the window opened with the Customize page level permissions... button.

2014 SQL Maestro Group

Security settings

6.5

115

Record-level security
Use the Record level permissions window to let each user access only to his own data.
The feature is available for table-based and hard-coded authorization types. To
implement the row level security to a webpage based on a table or a view,

make sure the table contains a column with owner information;

specify this column as the Owner field name and set the necessary permissions
for the record owner and for other users. In case of table-based authorization a
record will be displayed on the page if the owner field is equal to the ID of logged
used. If hard-coded authorization has been used the owner field means the name
of specified user

2014 SQL Maestro Group

107

116

PHP Generator for MySQL Help

Interface language
By default a web application created with PHP Generator for MySQL has English interface
but it can be localized (i.e. translated) for a number of languages. The text strings to be
used in the application's interface are stored in a localization file. To use a specific
language, select the corresponding file on the last wizard step. In case you use the
same file on a regular basis, it is recommended to specify it in the application output
options 126 to enable it by default.
Using prepared localization files
PHP Generator for MySQL comes with a number of localization files that can be found
under the installation folder, usually C:\Program Files\SQL Maestro Group\PHP Generator
for MySQL or C:\Program Files (x86)\SQL Maestro Group\PHP Generator for MySQL if you
have a 64-bit operation system installed on your computer. The table below contains
currently available files and the corresponding interface languages:
lang.br.php

Brazilian

lang.cs.php

Czech

lang.de.php

German

lang.dk.php

Danish

lang.en.php

English

lang.es.php

Spanish

lang.fr.php

French

lang.hu.php

Hungarian

lang.it.php

Italian

lang.nl.php

Dutch

lang.pl.php

Polish

lang.ru.php

Russian

lang.se.php

Swedish

lang.sk.php

Slovak

lang.sl.php

Slovenian

lang.sr.php

Serbian

lang.tr.php

Turkish

These files were sent to us by our customers and we are not responsible for their
quality. If none of these files is right for you, it is possible to customize the localization
as described below. We will be very appreciated if you send us your custom file to be
enjoyed by all the PHP Generator for MySQL users.
Using a custom localization file
If none of supplied files is appropriate for your application, you can create the
localization yourself. For this purpose get a localization file the clearest for you, enter/

2014 SQL Maestro Group

Interface language

117

correct necessary captions with any text editor, and save it in the UTF-8 encoding
(this is very important for the correct displaying of captions in a web browser).
Example
Suppose we need to create a web application in Esperanto. First we need to define the
localization file that is the clearest for us. In our case it is lang.en.php. Let's open the
file with a text editor (we prefer Notepad++), translate all captions to Esperanto, select
the UTF-8 encoding and save it as lang.eo.php (eo is the two-char language code for
Esperanto). All we need to do is select this file at the last wizard step and generate the
application. The result is shown below.

2014 SQL Maestro Group

118

PHP Generator for MySQL Help

Common generation options


At the last wizard step you can specify header and footer
and define security settings 105 of the created application.

100

, set a localization file

116

Access driver
There are several PHP drivers to communicate with database servers and PHP Generator
for MySQL allows you to select a driver to be used by the generated web application.
Note that the corresponding set of PHP functions should be available on your web
server. By default the driver is set in accordance with the application output options 126 .
Output directory
Generated files will be created in the output directory stored on your computer. To see
the result of the process, open any prepared .php file with any browser. Note, that to
run PHP code you need to have PHP and Apache installed or to run any portable web
server. To place the result webpages to the Internet, copy the created directory to
your hosting.
Generation options
To make the repeated generating process more fast, it's recommended to avoid
repeated copying
of
non-changeable
system files
stored in components,
database_engine, images, libs folders. These files must be rewritten only in case they
were generated by the former version of PHP Generator for MySQL.

2014 SQL Maestro Group

Common generation options

2014 SQL Maestro Group

119

120

PHP Generator for MySQL Help

Options
PHP Generator for MySQL allows you to customize the way it works within the Options
dialog. To open the dialog, use the More button and select Options at the drop-down
list.
The window allows you to customize the options grouped by the following sections:
Application 121
General PHP Generator for MySQL options: generation rules, default page options,
and display data formats.
Editors & Viewers 129
Customizing of all the SQL editors.
Appearance 137
Customizing program interface - bars, trees, menus, etc.
It is a good idea to check through these settings before you start working with PHP
Generator for MySQL. You may be surprised at all the things you can adjust and
configure!

2014 SQL Maestro Group

Options

9.1

121

Application
The Application section allows you to customize common rules of PHP Generator for
MySQL behavior. The section consists of several tab; follow the links to find out more
about each of them.
Page

121

Generation defaults
Display formats
Output

9.1.1

124

125

126

Page
Page navigator
Use this options group to define the number of records represented on the generated
page and the positioning of the navigational elements. The default navigational elements
are the numbers of pages. Use Data Partitioning 89 to create a custom pagination.
To display data more correctly, it's recommended to define the Content encoding of
data (UTF-8 or ANSI).
Content encoding
Specify the UTF-8 encoding to create a Unicode application.
Control buttons position
Select whether the Edit, View, Delete, and Copy buttons to be displayed on the left side
of the generated page or on the right one.
Visual effects enabled
If the option is 'OFF', all the javascript animation is disabled.
Page list mode
This option value determines whether the application navigation to be expanded,
collapsed or disabled.
To enable the list of all created webpages to be displayed at the Navigation bar of
webpage and to allows the highlighting of rows at mouse over check the corresponding
options.
Check the Use images for actions option to enable control buttons. If the option is not
checked the actions are available via corresponding links.
To enable the Set NULL checkboxes on editing/inserting data, turn ON the according
option.
The position and alignment of the Navigation bar, Page Caption and Page header are also
can be modified. Use for this purpose the direction of page option.
Specify the default criteria for Simple search default filter.

2014 SQL Maestro Group

122

PHP Generator for MySQL Help

The Use fixed grid header option allows to set the grid header will be represented at the
page on scrolling.
Check the Show line numbers option to add row numbering to the grid.
The Disable custom ordering option disallow users to sort data in the grid.
Apply filter automatically
This option allows you to define whether the filter condition specified in the Filter row
will be applied automatically, i.e. without using the Enter button. The Time interval
value determines the number of milliseconds passed from the last keystroke to the time
the filter is applied.

Use the Export tab to specify the available file formats the grid data may be exported to.

2014 SQL Maestro Group

Options

123

The Abilities options define the interaction between generated scripts and users. Here you
can specify the way data manipulations such as View, Edit, Copy and Insert to be
available for execution on the generated page: the ability is disabled, available on a
separated page, performed inline or in a modal dialog. You can also provide the prepared
page with ability to delete rows, the multiple deletion of rows using checkboxes, add
quick search to find the specified criteria in the whole of grid data, add a filter row - an
additional grid row to set filter conditions to each column, and filter builder to specify any
difficult filter conditions.

2014 SQL Maestro Group

124

9.1.2

PHP Generator for MySQL Help

Generation defaults
Use this tab to define the rules to be used for the page generation. These options allow
you to enable the setting of lookups and details by foreign keys, the editing of
autoincrement fields and inserting data into them, setting binary fields as images, and
allow setting the default field values on editing.
You can enable text area area for VARCHAR fields if their length is greater than Min
length value.
Specify here the Max visible length of text fields value. If the text length is greater than
this value, the residual text will be hidden under the More... link on the generated page.
Full text can be displayed in the special window in this case.

2014 SQL Maestro Group

Options

9.1.3

Display formats
Use this tab's fields to adjust the display data formats in the way you need.

2014 SQL Maestro Group

125

126

9.1.4

PHP Generator for MySQL Help

Output
Use this tab to specify default values for project output options

118

PHP Driver
There are several PHP drivers to communicate with database servers and PHP Generator
for MySQL allows you to select a driver to be used by the generated web application.
Note that the corresponding set of PHP functions should be available on your web
server.
Localization file
Use this field to define the interface language to be used for the generated application
by default. Find out more on applications localization at the corresponding page 116 .
You can also set here the output file extension and the default color scheme for the
generated pages.

2014 SQL Maestro Group

Options

9.1.5

127

Confirmations
This tab allows you to disable/enable application confirmations. Check corresponding
options to enable necessary confirmation dialogs such as key column notification, exit
from application confirmation and others.

2014 SQL Maestro Group

128

PHP Generator for MySQL Help

2014 SQL Maestro Group

Options

9.2

129

Editors & Viewers


The Editors & Viewers section allows you to set the parameters of viewing and editing
the SQL statements within PHP Generator for MySQL.
General
Display

9.2.1

129
130

SQL highlight

131

PHP highlight

133

XML highlight

132

Code Insight

134

Code Folding

135

General
If the Auto indent option is checked, each new indention is the same as the previous
when editing SQL text.
Insert mode
If this option is checked, insert symbols mode is default on.
Use syntax highlight
Enables syntax highlight in the object editor window.
Always show links
If this option is checked, hyperlinks are displayed in the editor window. To open a link
click it with the Ctrl button pressed.
Show line numbers
If this option is checked, line numbers are displayed in the SQL text editor window.
Use smart tabs
With this option on the number of tab stops is calculated automatically, depending on
the previous line tab.
Tab Stops
Defines the tab length, used when editing text.
Undo Limit
Defines the maximum number of changes possible to be undone.

2014 SQL Maestro Group

130

9.2.2

PHP Generator for MySQL Help

Display
You can disable/enable the right text margin and the gutter of the editor area, set the
position of the right text margin as Right margin, and the Gutter width.
Use the Editor font and Font size to define the font used in all program editors and
viewers. The panel below displays the sample of the selected font.

2014 SQL Maestro Group

Options

9.2.3

131

SQL highlight
Use the SQL highlight item to customize syntax highlight in all SQL editors and viewers.
Select the text element from the list, e.g. comment or SQL keyword and adjust its
foreground color, background color and text attributes according to your preferences.

2014 SQL Maestro Group

132

9.2.4

PHP Generator for MySQL Help

XML highlight
Use the XML highlight item to customize XML syntax highlight for the text representation
of BLOBs. Select the text element from the list, e.g. attribute or attribute value and
adjust its foreground color, background color and text attributes according to your
wishes.

2014 SQL Maestro Group

Options

9.2.5

133

PHP highlight
Select the text element from the list (e.g. Keyword, Comment, Identifier), and adjust its
foreground color, background color and text attributes according to your wishes.

2014 SQL Maestro Group

134

9.2.6

PHP Generator for MySQL Help

Code Insight
You can disable/enable the code completion with the corresponding option and also set
the time is appears as Delay, and case of words inserted automatically.

2014 SQL Maestro Group

Options

9.2.7

135

Code Folding
The Code Folding item group makes it possible both to view the whole text and to divide
it into logical parts (regions). Each part can be collapsed and extended. In extended
mode the whole text is displayed (set by default), in collapsed mode the text is hidden
behind one text line denoting the first line of the collapsed region.

2014 SQL Maestro Group

136

PHP Generator for MySQL Help

You can enable/disable code folding in SQL editors and viewers and customize the colors
of its items.

2014 SQL Maestro Group

Options

9.3

137

Appearance
The Appearance section allows you to customize the application interface style to your
preferences.
Use the Scheme name box to select the interface scheme you prefer: Office XP style,
Windows XP native style, etc. You can create your own interface schemes by
customizing any visual options (Bars and menus, Trees and lists, Edit controls, Check
boxes, Buttons, etc.) and clicking the Save As button. All the customized options are
displayed on the sample panel.
Bars and menus
Trees and lists
Edit controls

139

Check boxes

140

Buttons

Group boxes

9.3.1

138

141

Page controls

Splitters

137

142

143

144

Bars and menus


Use the Bars and menus item to customize PHP Generator for MySQL toolbars style and
menus animation.
The item allows you to select Bar style and menu animation from the corresponding
drop-down lists and to enable or disable such options as sunken border, F10 key for
opening menu, viewing full menus after delay, flat close buttons, gray-scale images.

2014 SQL Maestro Group

138

9.3.2

PHP Generator for MySQL Help

Trees and lists


Use the Trees and lists item to select various tree view options. Use the item to select
standard, flat or ultraflat styles, check or uncheck the hide selection, hide focus
rectangle and native style options.

2014 SQL Maestro Group

Options

9.3.3

139

Edit controls
Use the Edit controls item to customize the appearance of different PHP Generator for
MySQL edit controls. The tab allows you to select the edit controls border style, button
style and transparency, enable/disable hot tracks, shadows, native style and customize
edges. It is also possible to define samples for the text edit, button edit and combo box
controls.

2014 SQL Maestro Group

140

9.3.4

PHP Generator for MySQL Help

Check boxes
The Check boxes item allows you to customize the appearance of check boxes and radio
buttons. The tab allows you to customize the appearance of check boxes: set border
style, enable/disable hot tracks, shadows, native style. It is also possible to define
samples for check boxes and radio buttons.

2014 SQL Maestro Group

Options

9.3.5

141

Buttons
Use the Buttons item to customize PHP Generator for MySQL buttons. The tab allows
you to adjust the appearance of buttons and define sample buttons as well.

2014 SQL Maestro Group

142

9.3.6

PHP Generator for MySQL Help

Page controls
The Page controls item allows you to customize the style of all PHP Generator for MySQL
page controls. The tab allows you to select tab styles, enable/disable hot track, multiline pages and native style.

2014 SQL Maestro Group

Options

9.3.7

143

Group boxes
Use the Group boxes item to customize all PHP Generator for MySQL group boxes
according to your preferences. Use tab to apply styles for group boxes, enable/disable
native style and define samples.

2014 SQL Maestro Group

144

9.3.8

PHP Generator for MySQL Help

Splitters
Use the Splitters item to customize all PHP Generator for MySQL splitters according to
your preferences. Use the tab to select hot zone style (Windows XP task bar, Media
Player 8, Media Player 9, Simple or none) and specify the Hot zone drags a splitter
option.

2014 SQL Maestro Group

Options

2014 SQL Maestro Group

145

146

PHP Generator for MySQL Help

Index

-IInstallation instructions

-A-

-L-

Appearance Options
Bar and menus 137
Buttons
141
Check boxes
140
Edit controls
139
Group boxes 143
Page controls
142
Splitters
144
Trees and lists
138

License Agreement

Options 120
Appearance 137
Application
121
Editor & Viewers 129
Page 121

-P-

Command line options 17


Connect to database
12
Connection options 12

-E-

-GGetting started
11
Global Events 60
OnAfterLogin 61
OnBeforeDeleteRecord 63
OnBeforeInsertRecord 62
OnBeforeUpdateRecord 62

-O-

-C-

Editor & Viewer Options


Code Folding 135
Code Insight 134
Display
130
General 129
PHP highlight 133
SQL highlight 131
XML highlight 132
EULA
5
Events 59
Global Events 60
Page Events executed at Client Side
Page Events executed at Server Side

59, 63
59, 71

Page Editor
Columns 26
Data Partitioning 89
Edit properties
34
Events 59
Filter
87
Inline edit properties 50
Inline insert properties 50
Lookup options 27
Master- Detail Presentations 55
Multi-level autocomplete editor 44
Page properties 88
Templates 51
View properties 31
Page Events executed at Client Side 63
OnAfterPageLoad 64
OnBeforePageLoad 64
OnEditFormEditorValueChanged 67
OnEditFormLoaded 70
OnEditFormValidate 65
OnInsertFormEditorValueChanged 66
OnInsertFormLoaded 69
OnInsertFormValidate 65
Page Events executed at Server Side 71
OnAfterDeleteRecord 85, 86
OnAfterUpdateRecord 84
OnBeforePageExecute 72
OnCustomDrawRow 83
2014 SQL Maestro Group

Index

Page Events executed at Server Side 71


OnCustomHTMLHeader 76
OnCustomRenderColumn 72
OnCustomRenderExportColumn 75
OnCustomRenderPrintColumn 75
OnCustomRenderTotals 78
OnExtendedCustomDrawRow 76
OnGetCustomTemplate 79
PHP Generator for MySQL
Installation
3
License agreement 5
Overview 1
Registration 4
System requirements
2
Projects
16
Purchase PHP Generator for MySQL 4

-RRegistration 4
Report sending 18

-SSystem requirements

-WWebpage appearance 96
Color Scheme 99
Color Scheme Customization 99
Custom CSS
101
Custom templates
103
Header and Footer 100
Using templates
103
Working with PHP Generator for MySQL
Adding queries 23
Advanced generation options 118
Configuring datasources 20
Customizing content of webpages 25
Localization
116
Output folder 118
Page Editor
26
Project Options
94
Record-level security 115
Security options
105
Selecting tables and views 22
2014 SQL Maestro Group

User permissions
112
Webpage appearance 96

147