How PHP and MySQL Work Together?

PHP provides the application part, and MySQL provides the database part of a Web database application. You use the PHP language to write the programs that perform the application tasks. PHP is flexible enough to perform all the tasks that your application requires. It can be used for simple tasks (such as displaying a Web page) or for complicated tasks (such as accepting and verifying data that a user typed into an HTML form). One of the tasks that your application must do is move data into and out of the database and PHP has built-in features to use when writing programs that move data into and out of a MySQL database.

PHP statements are embedded in your HTML files with PHP tags. When the task to be performed by the application requires storing or retrieving data, you use specific PHP statements designed to interact with a MySQL database. You use one PHP statement to connect to the correct database, telling PHP where the database is located, its name, and the password needed to connect to it. The database doesnt need to be on the same machine as your Web site;

PHP can communicate with a database acr across a network. You use another PHP statement to send instructions to MySQL. You send an SQL message across the connection, giving MySQL instructions for the task that you want done. MySQL returns a status message that shows whether it successfully performed the task. If there was a problem, it returns an error message. If your SQL message asked to retrieve some data, MySQL sends the data that you asked for, and PHP stores it in a temporary location where it is available to you.

You then use one or more PHP statements to complete the application task. For instance, you can use PHP statements to display data that you retrieved. Or you might use PHP statements to display a status message in the browser, informing the user that the data was saved.

As an RDBMS, MySQL can store very complex information. As a scripting language, PHP can perform very complicated manipulation of data, either data that you need to modify before saving it in the database or data that you retrieved from the database and need to modify before displaying or using it for another task. Together, PHP and MySQL can be used to build a Web database application that has a very sophisticated and complicated purpose.

How PHP Works?

PHP is an embedded scripting language when used in Web pages. This means that PHP code is embedded in HTML code. You use HTML tags to enclose the PHP language that you embed in your HTML file the same way that you would use other HTML tags. You create and edit Web pages containing PHP the same way that you create and edit regular HTML pages. The PHP software works in conjunction with the Web server. The Web server is the software that delivers Web pages to the world. When you type a URL into your Web browser, youe sending a message to the Web server at that URL, asking it to send you an HTML file. The Web server responds by sending the requested file. Your browser reads the HTML file and displays the Webpage. You also request the Web server to send you a file when you click a link in a Web page. In addition, the Web server processes a file when you click a Web page button that submits a form.


When PHP is installed, the W Web server is configured to expect certain file extensions to contain PHP language statements. Often the extension is .php or .phtml, but any extension can be used. When the Web server gets a request for a file with the designated extension, it sends the HTML statements as-is, but PHP statements are processed by the PHP software before they are sent to the requester. When PHP language statements are processed, only the output is sent by the Web server to the Web browser. The PHP language statements are not included in the output sent to the browser, so the PHP code is secure and transparent to the user. For instance, in this simple PHP statement:

<?php echo “<p>Hello World”; ?>

is the closing tag. echo is a PHP instruction that tells PHP to output the upcoming text. The PHP software processes the PHP statement and outputs this:

<p>Hello World

which is a regular HTML statement. This HTML statement is delivered to the user browser. The browser interprets the statement as HTML code and displays a Web page with one paragraph Hello World. The PHP statement is not delivered to the browser, so the user never sees any PHP statements.

PHP and the Web server must work closely together. PHP is not integrated with all Web servers, but it does work with many of the most popular Web servers. PHP is developed as a project of the Apache Software Foundation par consequently, it works best with Apache. PHP also works with Microsoft IIS/

PWS, iPlanet (formerly Netscape Enterprise Server), and others. Although PHP works with several Web servers, it works best with Apache. If you can select or influence the selection of the Web server used in your organization, select Apache. By itself, Apache is a good choice. It is free, opensource, stable, and popular. It currently powers over 60 percent of all Websites, according to the Web server survey at www.netcraft.com. It runs on Windows, Linux, Mac OS, and most flavors of Unix.

What Is a Web Database Application?

An application is a program or a group of programs designed for use by an end user (for example, customers, members, circus acrobats, and so on). If the end user interacts with the application via a Web browser, the application is a Web-based or Web application. If the Web application requires the longterm storage of information, using a database, it is a Web database application. This book provides you with the information that you need to develop a Web database application that can be accessed with Web browsers such as Internet Explorer and Netscape.

A Web database application is designed to help a user accomplish a task. It can be a simple application that displays information in a browser window (for example, it displays current job openings when the user selects a job title) or a complicated program with extended functionality (for example, the book-ordering application at Amazon.com or the bidding application at eBay). Not surprisingly, a Web database application consists of a database and an application — just two pieces:

Database: The database is the long-term memory of your Web database application. The application can fulfill its purpose without the database. However, the database alone is not enough.

Application: The application piece is the program or group of programs that performs the tasks. Programs create the display that the user sees in the browser window; they make your application interactive by accepting and processing information that the user types in the browser window and they store information in the database and get information out of the database. (The database is useless unless you can move data in and out.)

The Web pages that you are previously created with HTML alone are static, meaning the user can interact with the Web page. All users see the same Web page. Dynamic Web pages, on the other hand, allow the user to interact with the Web page. Different users might see different Web pages. For instance, one user looking at a furniture store online product catalog might choose to view information about the sofas, whereas another user might choose to view information about coffee tables. To create dynamic Web pages, you must use another language in addition to HTML.

One language widely used to make Web pages dynamic is JavaScript. JavaScript is useful for several purposes, such as mouse-overs (for example, to highlight a navigation button when the user moves the mouse pointer over it) or accepting and validating information that users type into a Web form.

However, it not useful for interacting with a database. You wouldnt use JavaScript to move the information from the Web form into a database. PHP, however, is a language that is particularly well suited to interacting with databases. PHP can accept and validate the information that users type into a Web form and can also move the information into a database. The programs

in this book are written with PHP.

How to configure hyperlinks?

Links link one page to another page. They are essential if you site is composed of more than one page, or if you want to link to other sites on the Web. The example is an external link to a web site outside of this one. Showing the link in html code to design code.

Html code:

1) <a href="http://guideandtips.blogspot.com">Technomatic</a>
2) <a href="http://www.google.com">Google</a>


Design code:

Example 1 = Technomatic

Example 2 = Google