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

Subscribe to our news:
Partners
Testimonials
Steven Langfield: "I wanted to drop you a mail to say how freaking AMAZING your software is. It will be the best £100 I have ever spent. I have still to read all your documentation to take full advantage but what you have created is truly amazing".
Grey: "We're a two-person company, it's just me an my wife. I'm the technical guru, and she handles the business operations. I have to know a lot about MySQL, but that's much too technical for her. I have frequently had to setup CGI scripts (I code in Perl) so she can manage some of our tables (suppliers, manufacturers, etc).

I discovered PHP Generator a couple of days ago, tried the free version,and within a few hours I had purchased the Pro version (as well as SQL Maestro for MySQL).

Today I am completing the conversion of the last of my custom table managers to PHP Generator. This is eliminating several thousand lines of code that I don't have to support any more!

Thanks for this fantastic product".

More

Add your opinion

PHP Generator for MySQL online Help

Prev Return to chapter overview Next

Custom SQL queries

To use a SELECT query as a page data source, click 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%'

 

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;

 



Prev Return to chapter overview Next