You are on page 1of 66

Getting Star ted W ith PHPMagic

PHPMagic is a Application Development (RAD) tool for generating advanced PHP applications that connect to and manage data of MySQL databases. It also generates PHP code for creating the database itself as well. Once you get used to PHPMagic (which takes no time), you'll be able to create amazingly powerful web database applications -- even if you know nothing about PHP, SQL, MySQL, html, ... etc. PHPMagic does it all for you, automatically. PHPMagic 3 is the result of hundreds of user comments and feedback from people who used previous versions of PHPMagic. It is a whole new rebuild with many added features and a completely new and exciting look.

What will you find here?


A step-by-step guide to creating an online music database using PHPMagic. A guide to using the generated pages and dealing with the database. A last word.

GETTING

STARTED

WITH

PHPMAGIC

Creating your music albums online collection

In this section, I'll walk you through the simple steps needed to create your first PHPMagic application. We'll consider a real-world database application as an example: A music albums collection.

I have lots of music CDs that are actually collections of various singers. And I find it really hard sometimes to find a song that I wish to listen to. So, let's begin to create an application to manage this task. It shall also have the advantage of being an online application, which means you can put it on your web server and allow your friends to view it instead of asking you every time they want to borrow a CD if you have that song named bla bla bla. We'll create a Singers table, a CDs table and a Songs table. You might wonder: Why don't I create one table for all the data?? Well ... dividing the data into several tables instead of one is called data normalization. Data normalization helps decrease the database size and retain data integrity. In brief, you create a table for each object in your system. So, songs are an object, singers another object and CDs a third object. For more information about data normalization and other relational database design issues, I recommend you read the great tutorial by Selena Sol on databasejournal.com. (If you are not familiar with database design concepts, I highly recommend you check this tutorial before you continue reading this guide). http://www.websitedatabases.com/ 2

GETTING

STARTED

WITH

PHPMAGIC

Singers table shall have four fields: Singer number (automatically-incremented primary key) Singer name Country Comments CDs table shall have these fields: CD number (automatically-incremented primary key) Creation date CD name (I like to give names to my CDs: Meditation, Night slows, Shadow, .. etc) Comments And Songs table shall have these fields: Song Number (automatically-incremented primary key) Song name Singer (a foreign key field that accepts data only if it matches 'Singer number' field of the Singers table) CD (a foreign key field that accepts data only if it matches 'CD number' field of the CDs table)

Are you ready to begin now? Great .. let's go on step by step ...

http://www.websitedatabases.com/

GETTING

STARTED

WITH

PHPMAGIC

When you start PHPMagic, you see an empty working area. Click on the 'New Project' icon to start a new project.

Please note: This screenshot and all others are taken from PHPMagic version 1.0. Some icons you see have been changed in later versions of PHPMagic and the Trial version. However, you can create the entire example application shown here using the free trial version. Many new features have been added but the functionality is basically the same. This is simply a demo of how the application works.

http://www.websitedatabases.com/

GETTING

STARTED

WITH

PHPMAGIC

The project window is displayed. It has two panels. The left panel is the Project Browser and contains a hierarchical view of your database. Now it has only one item: the database itself. The default name of the database is new_db. The right panel is the Properties panel and it contains information about the currently-highlighted item in the Project Browser.

http://www.websitedatabases.com/

GETTING

STARTED

WITH

PHPMAGIC

Click twice (but not double-click) on the item 'new_db', or press F2, to change the database name. Well change it to 'music'.

http://www.websitedatabases.com/

GETTING

STARTED

WITH

PHPMAGIC

After typing the new name, click anywhere in the window to accept the new name.

http://www.websitedatabases.com/

GETTING

STARTED

WITH

PHPMAGIC

We then define the connection parameters for the database. Simply type the server name or IP, the username and the password in the Properties panel. If you don't know these values, contact your server administrator.

http://www.websitedatabases.com/

GETTING

STARTED

WITH

PHPMAGIC

Next, we create the tables of the database. Click on the 'New Table' icon.

http://www.websitedatabases.com/

GETTING

STARTED

WITH

PHPMAGIC

Now 'table1' is created. To change its name highlight the table in the Project Browser and press F2 or click on it.

http://www.websitedatabases.com/

10

GETTING

STARTED

WITH

PHPMAGIC

We rename it to 'singers'.

http://www.websitedatabases.com/

11

GETTING

STARTED

WITH

PHPMAGIC

We'll create another table, 'cds' in the same manner.

http://www.websitedatabases.com/

12

GETTING

STARTED

WITH

PHPMAGIC

Well rename the table to cds.

http://www.websitedatabases.com/

13

GETTING

STARTED

WITH

PHPMAGIC

And another table that we will rename to 'songs' in the same way as shown before.

http://www.websitedatabases.com/

14

GETTING

STARTED

WITH

PHPMAGIC

We'll adjust some properties for each table now. The Caption property is the title of the table that users of your application will see. Users wont see the actual name of the table since it has many restrictions (lower case letters, no spaces, no special characters, .. etc). But the caption can be almost anything you want (except single quotation marks). Youll see this same behavior in field names too.

http://www.websitedatabases.com/

15

GETTING

STARTED

WITH

PHPMAGIC

We have just changed the caption of the 'singers' table to 'Singers Table'.

http://www.websitedatabases.com/

16

GETTING

STARTED

WITH

PHPMAGIC

And the caption of the 'cds' table to 'CDs Table', and 'songs' table to 'Songs Table'.

http://www.websitedatabases.com/

17

GETTING

STARTED

WITH

PHPMAGIC

We'll now create some fields. We select the 'singers' table and then click on the 'New Field' icon to create a new field in the selected table.

Voila! 'field1' is created. We'll change the new field name by selecting it and pressing F2.

http://www.websitedatabases.com/

18

GETTING

STARTED

WITH

PHPMAGIC

We changed the name to 'singer number'.

http://www.websitedatabases.com/

19

GETTING

STARTED

WITH

PHPMAGIC

We'll now edit some properties of the selected field in the Properties panel.

http://www.websitedatabases.com/

20

GETTING

STARTED

WITH

PHPMAGIC

The field caption is changed to 'Singer Number'. A field caption is what your application users will see in their browser instead of the field name.

http://www.websitedatabases.com/

21

GETTING

STARTED

WITH

PHPMAGIC

We checked 'Primary key' so that the selected field becomes the primary key of the table. A primary key is a field used to uniquely identify each record in the table. For example, if we say the record whose primary key field is equal to 125587, then we are talking about one and only one record in the table. The singer number is going to be the primary key field of the singers table in our example.

http://www.websitedatabases.com/

22

GETTING

STARTED

WITH

PHPMAGIC

Auto Increment means the field will contain an automatic counter that increases whenever a new data record is added to the database. In most cases, primary key fields will also be auto-incremented.

http://www.websitedatabases.com/

23

GETTING

STARTED

WITH

PHPMAGIC

Let's create some more fields ...

And we rename it to singer_name in the same way we renamed tables before.

http://www.websitedatabases.com/

24

GETTING

STARTED

WITH

PHPMAGIC

Singer name will be a text field of type 'VarChar' and length 40.

http://www.websitedatabases.com/

25

GETTING

STARTED

WITH

PHPMAGIC

Then we create another field, country, and set its properties ...

If you have PHPMagic Professional, you can define several countries to choose from in the Value list box. This will let your users choose the country from a drop down menu instead of typing it.

http://www.websitedatabases.com/

26

GETTING

STARTED

WITH

PHPMAGIC

Here are all the fields created. 'singer' and 'cd' fields of the 'songs' table shall be foreign keys to link the 'songs' table to the 'singers' and 'cds' tables. Let's set this now ...

http://www.websitedatabases.com/

27

GETTING

STARTED

WITH

PHPMAGIC

We set the Parent table to 'singers', Parent ID field to the primary key field of the 'singers' table which is 'singer_number', and Parent caption field to 'singer_name' so that the users see the singer names instead of their serial numbers. Please note that the data type of the foreign key field must match that of its parent id field.

http://www.websitedatabases.com/

28

GETTING

STARTED

WITH

PHPMAGIC

We do the same with 'cd' field.

http://www.websitedatabases.com/

29

GETTING

STARTED

WITH

PHPMAGIC

That's all! Your project is ready for generation of the PHP application. Click on the 'Generate PHP code' icon, or press F5.

You're asked now to select an output folder where the application files will be created. It's recommended you select an empty folder or create a new folder in order not to mix any files. After selecting the output folder, PHPMagic generates the application files and displays a detailed log. Click 'Close' to close the window.

http://www.websitedatabases.com/

30

GETTING

STARTED

WITH

PHPMAGIC

Click the 'Exit' icon to quit PHPMagic. The next step is to upload the application to your web server and set it up. (http://yourdomain.com/your_phpmagic_folder/setup.php)

http://www.websitedatabases.com/

31

GETTING

STARTED

WITH

PHPMAGIC

Using The Generated PHP Application


This is the main page of the generated PHP application. It contains links to all the tables we created in our PHPMagic project. TIP! If you wish to change the look of this page, you can look for the file index.html in the generated files folder and open it in your favorite HTML editor and perform your magic!

http://www.websitedatabases.com/

32

GETTING

STARTED

WITH

PHPMAGIC

We shall try to view the 'Singers Table' page now.

http://www.websitedatabases.com/

33

GETTING

STARTED

WITH

PHPMAGIC

Oops!! We forgot to set up the database before trying to view its tables. However, PHPMagic reminds us of doing so and provides a link to the setup page.

http://www.websitedatabases.com/

34

GETTING

STARTED

WITH

PHPMAGIC

We'll click on the link to set up the database.

http://www.websitedatabases.com/

35

GETTING

STARTED

WITH

PHPMAGIC

Here we are! The database is created together with all the tables.

http://www.websitedatabases.com/

36

GETTING

STARTED

WITH

PHPMAGIC

We'll click on the provided link to return to the main page.

http://www.websitedatabases.com/

37

GETTING

STARTED

WITH

PHPMAGIC

And we click the 'Singers Table' again.

http://www.websitedatabases.com/

38

GETTING

STARTED

WITH

PHPMAGIC

This time it's working. We see now the 'Singers Table' page. Here we can view data records, add new records, edit and delete existing records, sort and filter records. But since this table is new, it is still empty. We shall now add a new data record.

http://www.websitedatabases.com/

39

GETTING

STARTED

WITH

PHPMAGIC

The Detail View at the bottom of the table allows us to enter data for the new record.

Note that the 'Country' field has a menu of allowable data values. This was done in PHPMagic Professional Edition by defining a values list for this field.

http://www.websitedatabases.com/

40

GETTING

STARTED

WITH

PHPMAGIC

We now click the 'Add New Record' button to save data to the table.

http://www.websitedatabases.com/

41

GETTING

STARTED

WITH

PHPMAGIC

The new record shows up in the table now. It is highlighted by a white background to indicate that it is the currently selected record.

Observe the new buttons that appear in the Detail View.

Notice also that Singer Number was automatically set to '1' since we defined this field as 'Auto Increment' in PHPMagic.

http://www.websitedatabases.com/

42

GETTING

STARTED

WITH

PHPMAGIC

We continue adding data records in the same manner.

http://www.websitedatabases.com/

43

GETTING

STARTED

WITH

PHPMAGIC

To select any record in the table for editing or deleting, simply click on it. We shall select 'Micheal Jakson' and edit his data.

http://www.websitedatabases.com/

44

GETTING

STARTED

WITH

PHPMAGIC

'Micheal Jakson' is now highlighted. The field data appear in the Detail View.

http://www.websitedatabases.com/

45

GETTING

STARTED

WITH

PHPMAGIC

We add a comment and then save changes by clicking the 'Update Record' button.

http://www.websitedatabases.com/

46

GETTING

STARTED

WITH

PHPMAGIC

The table is updated.

http://www.websitedatabases.com/

47

GETTING

STARTED

WITH

PHPMAGIC

We'll select another record.

http://www.websitedatabases.com/

48

GETTING

STARTED

WITH

PHPMAGIC

We'll delete 'Britney' from the table by clicking the 'Delete Record' button.

http://www.websitedatabases.com/

49

GETTING

STARTED

WITH

PHPMAGIC

A delete confirmation window pops up. We'll click 'Ok'.

http://www.websitedatabases.com/

50

GETTING

STARTED

WITH

PHPMAGIC

The record is removed from the table.

http://www.websitedatabases.com/

51

GETTING

STARTED

WITH

PHPMAGIC

The 'Print' button displays the table without the buttons and the detail view so that users can print it. We'll click this button now.

http://www.websitedatabases.com/

52

GETTING

STARTED

WITH

PHPMAGIC

This is the printer-friendly view. You can use your broswer's Back button to return to the previous view.

http://www.websitedatabases.com/

53

GETTING

STARTED

WITH

PHPMAGIC

The 'Edit Filters' button displays a filters page so that we can search the data in the table according to criteria we'll define.

http://www.websitedatabases.com/

54

GETTING

STARTED

WITH

PHPMAGIC

This is the filters page. We may define up to 10 filters. A filter begins with an 'And' or 'Or' to indicate how the filter is combined with other filters. Filters consist of a field name, a comparison operator and a comparison value ...

http://www.websitedatabases.com/

55

GETTING

STARTED

WITH

PHPMAGIC

For example, here we want to view singers from USA only.

http://www.websitedatabases.com/

56

GETTING

STARTED

WITH

PHPMAGIC

To apply your filter(s), click the 'Apply Filters' button.

http://www.websitedatabases.com/

57

GETTING

STARTED

WITH

PHPMAGIC

Here we are!

http://www.websitedatabases.com/

58

GETTING

STARTED

WITH

PHPMAGIC

The 'Clear Filters' button removes all filters.

http://www.websitedatabases.com/

59

GETTING

STARTED

WITH

PHPMAGIC

The table shows all data now without filters.

http://www.websitedatabases.com/

60

GETTING

STARTED

WITH

PHPMAGIC

PHPMagic allows us to sort data by any field. Simply click on the field header.

http://www.websitedatabases.com/

61

GETTING

STARTED

WITH

PHPMAGIC

Data is now sorted ascendingly by singer name.

http://www.websitedatabases.com/

62

GETTING

STARTED

WITH

PHPMAGIC

If we click the 'Singer Name' header again, sorting will be discending.

http://www.websitedatabases.com/

63

GETTING

STARTED

WITH

PHPMAGIC

Here it is!

http://www.websitedatabases.com/

64

GETTING

STARTED

WITH

PHPMAGIC

The 'Select A Table' menu allows you to view any other table by selecting it. By now we have reached the end of our Getting Started guide. Try PHPMagic on your own now and see for yourself the possibilites and powers. Context help is availble everywhere in PHPMagic by clicking F1 anytime. Enjoy!

http://www.websitedatabases.com/

65

GETTING

STARTED

WITH

PHPMAGIC

A Last Word.
By now, Im sure you have realized the power of PHPMagic. Many PHPMagic users create powerful web-enabled databases having tens and even hundreds of tables. You can do it without a single line of code. No need to spend hundreds of hours writing SQL, PHP or HTML code. No need to hire expensive programmers to do it for you either. And even if you need to customize the generated files, you know you wont have to start from scratch. You know that you have already saved yourself tons of programming time and effort. The generated code is very neat and easy to understand. Many customers told us that they used it to learn PHP! Now, think of it: Isnt saving yourself hundreds of hours in programming, thousands of dollars in programmers costs, endless testing and debugging efforts isnt saving all of these worth a little investment in PHPMagic?

Order Now!

http://www.websitedatabases.com/

66

You might also like