CHAPTER

10

Appendix

Chapter Objectives

• Introduce web servers

• Describe web server pages

• Discuss various server technologies for web server applications

• Discuss the MySQL database for web applications

10.1 Overview

 

Ajax can be used by web clients to communicate with web servers asynchronously versus synchronously so that Ajax can make the data exchanges between web clients and servers much more efficient for large-volume data updates. In this appendix you will learn some popular web server technology that Ajax clients have used widely in current web applications.

This appendix introduces the open-source web servers, web server page development kits, Apache web servers, PHP server pages, Java-based Net-Beans with its built-in Tomcat web servers, and the popular MySQL database.

Step-by-step tutorials are also provided in this appendix for readers to practice.

10.2 Firebug

 

Firebug is an excellent web development tool that is an add-on for Firefox. It provides the developer with many tools to inspect, edit, debug, and profile web pages. Installing Firebug is easy. Here are the steps.

1. Navigate your Firefox browser to http://www.getfirebug.com and click on the orange square that reads “Install Firebug”. (If your browser is configured to prevent pop-up windows, you will need to modify your settings to allow pop-ups from this website and then click on the square again.) After Firebug is downloaded, Firefox will display a window with an Install button. Click on Install to install Firebug. When the installation is complete, you will be required to restart Firefox for Firebug to work.

images

2. After Firefox has restarted you can open Firebug and check it out by selecting Tools → Firebug → Open Firebug from the browser menu or by pressing the F12 key.

images

3. Once Firebug is open, you can select the HTML tab to inspect the web page's HTML and CSS. You can even edit the CSS and see the change immediately reflected in the web page. The ability to tweak CSS like this is one of Firebug's most useful features.

images

4. You can also select the Script tab to see the JavaScript code for the web page. From this tab you can also set breakpoints in the JavaScript code to step debug. Just click on the line number where you want to set the breakpoint and then reload the page, or do whatever is required to get the code to execute, like clicking on a button. Firebug will stop the JavaScript execution at the breakpoint and you can use the buttons above the Breakpoints tab to step through the code.

images

5. Firebug is a great tool for experimenting with not only CSS but also JavaScript. If you click on the Console tab, you will get a command line in which you can enter JavaScript code to experiment with the DOM.

images

Firebug is used in some of the chapters and is well worth installing and getting familiar with. It is a tool that you really cannot beat. For more information, check out the documentation on the Firebug website, in particular the JavaScript debugging tool (http://www.getfirebug.com/js.html).

10.3 Apache

 

10.3.1 Overview of Apache Web Server

Apache is a popular open-source HTTP-compliant web server developed by the Apache Software Foundation. More than 60% of websites in the world use Apache. Many commercial vendors have adopted Apache-based solutions for their products, including Amazon, Yahoo, IBM, Red Hat, and ORACLE.

The Apache development group said: The Apache HTTP Server Project is an effort to develop and maintain an open-source HTTP server for modern operating systems including UNIX and Windows NT. The goal of this project is to provide a secure, efficient and extensible server that provides HTTP services in sync with the current HTTP standards.

The Apache server is a powerful, flexible, HTTP/1.1 compliant web server which

images implements the latest protocols, including HTTP/1.1

images is highly configurable and extensible with third-party modules

images can be customized by writing ‘modules’ using the Apache module API

images provides full source code and comes with an unrestrictive license

images runs on Windows, Netware 5.x and above, OS/2, and most versions of Unix, as well as several other operating systems

images is actively being developed

images encourages user feedback through new ideas, bug reports and patches

Apache is constructed in a Module architecture. A module can be reused to develop other modules, protocols, or applications. A new module can be written in any Apache-supported language. This feature greatly increases its adaptability, extensibility, scalability, and flexibility, making Apache much more powerful.

Apache server security is another important feature. It has modules to support the Secure Socket Layer (SSL) and Transport Layer Security (TLS) protocols that allow data between the web server and the client to be encrypted. Also, Apache has modules to support Authentication and Access Control to authenticate against plain text and database files. It also provides authentication to determine the identity of a client, usually by verifying a username and password against a back-end database.

Apache's scalability is supported by Load Balancing, and Request Redirection is another advantage that you gain with Apache.

Apache's stability is another reason for its popularity. Apache is portable, so it can run on almost any platform, including UNIX, Linux, Windows, and Mac OS X. The original Apache was developed based on the NCSA HTTPd web server for UNIX. Its name came from A Patchy server because it was developed from existing NCSA code with many patches.

Another important feature is its high performance with multiprocessing and multithreading. Apache can be configured in a pure process-based server mode, a purely threaded server mode, or a mixture of those two. One process can run multiple threads simultaneously. Threads can share data and code in memory within a process, but each process has its own dedicated memory space. There is a tradeoff in reliability between these two modes because of the resource sharing.

Apache is available for download at http://httpd.apache.org.

The current version of Apache supports web development platform integration, meaning that an Apache module can be written entirely in the integrated language platforms. Apache has several integrated modules that support web application development tools with the server such as Java and C#. Here is a list of Apache integrated development platforms.
 

images PHP (a popular Apache module) is a server-side, cross-platform, HTML-embedded scripting language that has many supporting modules, including a database connectivity module for popular databases such as ODBC, Oracle, MS-SQL server, MySQL, and PostgreSQL

images XML

images HTTP, FTP

images Directory support: LDAP

images PDF generation

images CORBA

images SNMP
 

Apache integrates Mono .NET and ASP .NET Microsoft frameworks and exposes the Apache API to the .Net framework so that developers can write modules in C#, or VB .NET and run .NET web applications on Apache instead of Microsoft IIS.

Many application servers, including Oracle Application server, IBM WebSphere, and BEA WebLogic, also provide modules to integrate with the Apache web server. Apache also integrates Java-based Tomcat to run all Java server-side applications such as servlets and JSP.

Apache has integrated modules to support many script languages such as PHP, JavaScript, Ruby, and Python for web applications as well. Apache web server also supports the MySQL database server.

A typical ideal web server configuration for Apache web application is the common acronym LAMP (Linux–Apache–MySQL–PHP).

Apache provides modules for web server administration tools for building, configuring, and monitoring different servers.

Apache provides many protocol modules such as SNMP (Simple Network Management Protocol) and FTP so that developers can use these modules to develop new protocols.

Apache provides virtual hosting so that multiple websites can run on an Apache server.

10.3.2 Apache Server Installation and Startup

This section introduces how to build an Apache HTTP web server for any web application. First, let us download the Apache web server and install it on a Windows machine.

Download Apache HTTP server from http://httpd.apache.org/download. cgi. You may want to select the Win32 Binary (MSI Installer) to install, and then you can refer to http://httpd.apache.org/docs/2.2/platform/ windows.html.

The most current Apache version is 2.x. The following is the download page for Apache.

images

Just follow the Apache installation instructions on the installation screen. Completing the installation should be easy. After you install Apache Server, you will see the following screen, which indicates that Apache Server is up and running.

images

Try to access http://localhost after Apache Server is installed and running. You will see the following:

images

10.4 PHP

 

10.4.1 Overview

PHP is just one of many popular web server-side open-source scripting languages. PHP is a perfect server scripting language to handle the Ajax XMLHttpRequest. It is widely used for web application development. There are more than half a million server pages developed by PHP. It is still growing fast.

PHP is often embedded into HTML to enhance HTML functions. PHP allows you to interact with an HTML page dynamically. PHP collects data from the page where the user provides information and then processes and uses the data to create dynamic home page output.

PHP can do all the tasks that ASP and JSP can do, and it is free. Why is PHP so popular?
 

images PHP is open source and free.

images PHP is much more compact than Java and .NET in terms of its system size.

images PHP is portable and runs on Linux, Windows, and Mac platforms.

images PHP is a server-side script language that is easily adopted.

images PHP has fast connections to popular databases compared with Perl.

images PHP is integrated with the open-source MySQL database.

images PHP is an object-oriented interpreter language.

images PHP web pages work with all popular major browsers.

images PHP has integrated linking to XML, PDF, SWF, and Java for dynamic creation and processing.

images PHP syntax is familiar to users of C, Perl, and Java.
 

PHP meshes with HTML well because PHP is designed to be used along with HTML. You can embed PHP into an HTML document or put HTML tags in PHP coding seamlessly.

PHP also gets along well with MySQL. These two make up the best combination for data-driven web application across platforms. PHP can also support a massive number of databases, including those based on Informix, Oracle, Sybase, and ODBC drivers.

10.4.2 Practice Lab for PHP Web Application on Apache

In this section, you will be given a hands-on lab on a “Hello user” Apache server and PHP web project. A PHP page based on an HTTP server page is populated on an Apache web server. If a web client accesses this page and fills in his or her name as <name>, then the PHP page will dynamically create a response page that responds with the greeting statement “Hello <name>”.

After installing Apache server, you can download and install PHP by accessing http://www.php.net/downloads.php. The installation manual at http://www.php.net/install.windows may be helpful. The binary installer is easy to use. However, if you want to use manual installation, you need to extract php 5.x into C:php. You may choose a different location, but do not leave any spaces in the path (like C:Program FilesPHP) because some web servers will crash if you do so.

In your php directory, there are two files: php.ini-dist and php.ini-recom-mended. Change one of them to php.ini (php.ini-recommended is preferred).

First, edit the php.ini file as follows:

images

Next, edit Apache configuration file httpd.conf. Add the following lines to it, and the PHP should work as a module:

images

The web page at http://www.ricocheting.com/server/php.html is a good getting-started tutorial.

You can create a file named test.php in your Apache default folder: C:Program FilesApache Software FoundationApache2.2htdocs The php template is shown as

images

Save your configuration and start up the Apache server. Go to http://localhost/test.php, and you will see the following:

images

Edit the HTML template provided by PHP as follows:

images

images

This is an HTML file with embedded php tag <?php ?>.

This php tag simply echoes the input name on the page. If you type “John” in the name box as follows,

images

you will see a PHP response page saying “Hello! John”.

images

10.4.3 PHP and Ajax with XAMPP

This tutorial shows the same “Hello user” example above implemented by Ajax client and PHP server interaction on an Apache server. The XAMPP (LinuX, Apache, MySQL, PHP, and Perl) is an Apache distribution containing MySQL, PHP, and Perl. XAMPP is easy to install and to use: just download, extract, and start. Here XAMPP is used, which comes with the precompiled Apache and PHP.

You can download XAMPP for Windows from http://www.apachefriends. org/en/xampp-windows.html.

Step 1:

First you need to extract XAMPP and double click the setup file to start the server.

images

The install wizard of XAMPP win32.

After installation is complete, go to the XAMPP folder. You can use the XAMPP Control Panel to start and stop all servers and to install and unin-stall services.

images

Step 2:

Open a browser and type http://localhost/.

You should find a page similar to the following figure. This shows that the server is running.

images

Inside the XAMPP folder, there is a folder named htdocs. Inside this folder, open Notepad and enter the following code.

 

1. Create a phpindex.php file as follows.

images

images

2. Create a new file ajax.php and type this code.

images

Step 3:

Now open the browser and type http://localhost/phpindex.php.

If you enter some name in the text field, the page responds to you automatically. You may have noticed that there is no submit button because the response is posted instantly and asynchronously by Ajax.

images

10.4.4 PHP and Ajax with WAMP

This tutorial shows the preceding “Hello user” example implemented with Ajax client and PHP server interaction on an Apache server. WAMP (Windows, Apache, MySQL, and PHP) is easy to install and to use: just download, extract, and start. SQLitemanager, the Phpmyadmin, comes along with WAMP, which gives a good user interface to manage MySQL.

You can download the latest version of WAMP Server from http://www.wampserver.com/en/.

Step 1:

First you need to run the WAMP setup program and extract it to your desired folder, for example, C:wamp.

To start the WAMP Server you start wampserver and then look near the taskbar to start Apache and MySQL Server. Now choose Start All Services.

images

Step 2:

To check whether the server has started, open a browser and type http://localhost/.

You find a page similar to the following figure. This shows that the server is running.

images

Inside the WAMP folder, there is a folder named www. Inside this folder, open Notepad and type the following code.

images

1. Create a phpindex.php file as follows.

images

images

2. Create a new file ajax.php and type this code.

images

Step 3:

Now open the browser and type http://localhost/phpindex.php. You could also type in http://localhost and browse through the projects and select phpindex.php.

If you enter some name in the text field, the page responds to you automatically. You may have noticed that there is no submit button because the response is posted instantly and asynchronously by Ajax.

10.5 NetBeans and Tomcat

 

10.5.1 Overview of NetBeans

The NetBeans IDE is a free, open-source Integrated Development Environment (IDE) for Java software developers. It covers all Java Standard Edition (Java SE), Java Enterprise Edition (Java EE, previously called J2EE), and Java Micro Edition (was called J2ME)—all in one IDE environment. This IDE runs on almost all platforms, including Windows, Linux, Solaris, and the Mac OS. It is easy to install, and developing Java-based cross-platform desktop, Enterprise, web, and mobile applications is convenient. It is also a useful component-based software development (CBSD) tool to create, reuse, and deploy Java JAR, WAR, and EAR components.

NetBeans provides the following:

 

images Swing GUI Builder, Integrated CVS Version Control, NetBeans Debugger with JUnit, Developer Collaboration for project sharing in real time, and Ant-based project system and customizable environment tools

images Source Code Editor for Java SE and JSP Development: XML Editor for DTD, Schema, and CSS; plus C/C++ development

images Web server application development tools with JSP, servlets, JavaServer Faces (JSF) and Struts (Java Enterprise Edition), Sun Application Server, Weblogic, and JBoss

images RJB developments with ear-jar deployment

images Visual web application development for Ajax, CSS, and JSF; Web Service Development (SOA) with Java Enterprise Edition for WSDL and web service implementation development and deployment; BEPL design, development, and testing tools

images Web client platform development

images Mobile application development (Java Micro Edition) including Connected Limited Device Configuration (CLDC), CDC, and Mobile Information Device Profile (MIDP); Java ME development cycle tools

images UML modeling tools with code generators

images Embedded Tomcat server

10.5.2 Practice Lab: Using JSP on Embedded Tomcat in NetBeans

First, download NetBeans from http://www.netbeans.org/. The current version is 6.X.

images

After installing NetBeans, start up the NetBeans IDE, and you should see the NetBeans start page as follows.

images

Once you have installed NetBeans, GlassFish 2.1 is the default server installed. If you prefer to run on a Tomcat server, we need to install that externally.

Installing and adding an external Tomcat server in NetBeans 6.0:

Reference: http://wiki.netbeans.org/AddExternalTomcat

It is assumed that Apache Tomcat NetBeans 6.0 and the latest JDK are installed. In NetBeans 6.0 we need to add the Tomcat server externally. Let us see the configuration of the Tomcat 6.0 server.

Tomcat 6.0 setup:

You can either install the executable file to install Tomcat 6.0 or you can extract the Tomcat6.0.zip folder to the drive; for example, you can extract it to C:Tomcat6.0.

Now you go into your Tomcatconf folder and open tomcat-users.xml in a text editor and add the username and password in which the manager role is assigned to the user.

Here is how your tomcat-users.xml should look:

images

This will add the username as admin and password as mypassword. In Net-Beans 6.0 we need to specify the username and password.

You will build the application by using JSP technology, and the work will be done in the NetBeans 6.0 IDE. Once the Tomcat server is installed properly, open the Netbeans 6.0 IDE to add the Tomcat as an external server.

Step 1: First choose the Services option and select Server; right-click the icon to add server.

images

Step 2: Select Tomcat 6.0 to add the Tomcat 6.0 server, which is installed already in the drive.

images

Step 3: Browse and select the Tomcat installation directory. It should be in the directory C:Tomcat6.0 if you have extracted to that folder. If you have installed the executable file it should be in the folder of Program files in the Apache Software Foundation directory.

images

Step 4: Click Finish. You should now be able to see Tomcat 6.0 under the Servers list.

images

Note: If you have installed the Tomcat executed file, the two files catalina.bat and setclasspath.bat might be missing in the Tomcatin folder. These two files are needed to start the Tomcat server from the NetBeans 6.0 IDE. If the two bat files are missing, you can get them from http://forum.java.sun.com/thread.jspa?threadID=664901&messageID=3893743 and then make these two .bat files available to start the server from NetBeans 6.0.

Steps to Start a Web Project:

Let us practice using the NetBeans IDE with the following steps to create a new web project. In this application Tomcat 6 is used as the server.

In first step, select File → New Project and Web → Web Application.

images

Next, specify the project name and project location in step #2 of “Name and Location”.

images

Skip step #3, Framework selections, for the time being.

In the file explorer, select Application name→web→index.jsp, and now we will make some changes to this template file.

images

Copy the following code in the body tag:

images

Press Run Main Project (F6). NetBeans will run the Tomcat server and you can use your browser to visit localhost to access this JSP file:

images

If you type in “John” in the text box and then submit the request, a new JSP page is generated with the greeting statement of “Hello, John”.

images

This lab shows that NetBeans IDE is another useful tool to develop server-side applications. Any Ajax JavaScript request can access such server components developed with the NetBeans IDE tool.

10.5.3 Ajax with JSP Developed in NetBeans

We assume that you have already installed Apache Tomcat and NetBeans IDE. You will build your Ajax server by using jsp technology, and the work will be done in NetBeans IDE.

Step 1: Start up NetBeans. Select File→New Project’.

images

Step 2: Select We b and Web Application, and then click Next.

In the new dialog box, name your project and choose a location for it. Click Finish when done.

You will see a default page, index.jsp, and the directory structure like the following where you can place “Hello World!” in the HTML body:

images

You can run this default page by clicking Run → Run Main Project.

It takes a few seconds to launch the built-in Java server. Also, the new jsp file needs to be compiled. After all, a new browser would open automatically with a simple page.

images

Step 3: Copy the following code to the default page index.jsp.

images

images

Step 4:

You launch the server by clicking Run → Run Main Project. In the new default page you can see a text area.

images

If you enter some name in the text area, the page responds to you automatically and immediately without your having to push a button.

images

You can find in this example that the Ajax client works in an asynchronous mode without loss of operation context rather than in the “click, wait, and refresh” request-response communication user interaction mode. The Ajax client only partially refreshes the updated portion of the page and gets instant feedback for the user's activities.

10.6 NetBeans PHP Plugin

 

In addition to being an excellent Java development platform, the NetBeans IDE has a PHP plugin that can aid with developing PHP web applications by providing syntax coloring, code completion, and debugging. It is fairly simple to install and set up. The first thing that you need in place is the Apache web server and PHP, which have already been covered in this Appendix. If you have not set them up yet, go back and follow the instructions for doing so.

The other important piece of software that you will want in place before installing the PHP plugin is the PHP debugger, available for download at http://www.xdebug.org/docs/install. Download XDebug and place it anywhere on your hard drive; then add the following to the php.ini file, but replace C:xdebugphp_xdebug-2.0.2-5.2.5.dll with the location of your copy of xdebug dll.

images

Now, to install and set up the PHP plugin, follow these steps.

1. Check if the PHP plugin is already installed: choose Tools → Plugins and switch to the Installed tab.

images

2. If PHP is not on the list of installed plugins, switch to the Available Plugins tab, select the PHP option in the list, and click the Install button.

3. In the NetBeans IDE main screen, switch to the Services tab, which shows a tree of available databases and web server profiles.

4. Position the cursor on the Web Servers node, and from the context menu choose Add Web Server. The Add New Web Server Record dialog box opens.

images

5. In the Connection Name text field, enter the name of the web server profile and from the Server Type drop-down list, and choose one of the connection types:

 

a. Local Web Server with File Access. This option assumes that you have a web server installed on your local computer. Every time that you run your PHP project, the IDE copies your source files to a specified directory under the web server document root. If you set up the Apache web server locally per the instructions earlier in this Appendix, then this is the option that you should choose.

b. Remote Web Server with FTP Access. This option allows you to deploy your PHP files to a remote web server via FTP.

images

6. Click Next and choose the Manual Configuration option.

7. In the Apache config file Location text box, specify the location of the httpd.conf file.

8. From the Choose Host Name drop-down list, select the relevant virtual host. In a development environment, only one choice is typically available.

9. To specify the server manually, from the Server Location dropdown list, choose the relevant server.

images

10. Click Next.

11. In the Base Directory text field, enter the subfolder of the Document Root where your PHP files will be copied. To deploy your web applications to the web server root, leave this field empty.

12. Click Finish.

Now you can create new PHP projects and deploy your project to the Apache web server to test.

1. In the Projects window, choose File → New Project.

2. The New Project wizard opens.

3. In the Categories list, select PHP.

4. In the Projects area, choose PHP Project to create an empty project and click Next. To use preexisting source files, choose PHP Project with Existing Sources.

images

5. At the Name and Location page, enter the name of the project in the Project Name field. NetBeans will automatically create a new folder for your project.

6. In the Project Location text field, specify the location for the new project folder or accept the defaults. Note: The contents of the fields change while you type in the Project Location text field.

7. Select the Set as Main Project checkbox if you have more than one PHP project in your project tree and want the current project to run first.

8. To create an index file, select the Create Index File checkbox and specify the field name in the text field.

9. Click Next. The Web Server Configuration dialog box opens.

images

10. From the Configured Web Servers drop-down list, choose the name of the appropriate web server profile. You can view the following settings for the selected web server profile:

 

1. HTTP Path, a host name or IP address of the HTTP server and the port number that the server listens to.

2. File access settings for the selected profile, which are the directories where the web server looks for files (Document Path if you are using a local server or FTP Path if you are using a remote server).

11. In the Context Path text fields, enter the name of the subfolder in the Document Root where you want your PHP files to be deployed.

For more information on the PHP plugin see http://php.netbeans.org/.

10.7 Ajax with ASP

 

You use ASP server in this example.

Step 1: Install IIS

Go to Control panel→Add or remove programs→Add or remove windows components, and select Internet Information Services to install IIS. If you already have IIS installed on your computer, you do not need to repeat this step. The installation asks for a Windows CD.

images

After you install IIS, you can find a new folder at C:Inetpub. It is the default folder of IIS. Open your Firefox and type http://localhost in the address field; press Enter. You can see the default page like this:

images

Step 2: Server-side file: asp

The default root folder of IIS is C:Inetpubwwwroot, which means that you can put your pages here and visit them from your browsers.

Create a new text file and name it hello.asp. This asp file runs at the IIS server and generates greetings for the users at the client side. If the users type “Bill”, they will see “Hello! Bill” below the text box.

Copy the following code to hello.asp and save (pay attention to the characters that Microsoft Word used; they may be invalid in your text editor):

images

images

Step 3: Make client-side files: html and js

The .htm and .js files, though stored at the server, will be downloaded and executed in the user's browser. You create two text files in the same folder of gethint.asp (C:Inetpubwwwroot), and name them testAjax.htm and clienthint.js. Here is the code for these two files:

testAjax.htm

images

clienthint.js

images

images

Step 4: Run the sample

Now you have an Internet server: IIS and three files (testAjax.htm, clienthint.js, gethint.asp) are in the default folder (C:Inetpubwwwroot).

images

With IIS running, open a browser (Firefox) and type http://localhost/testAjax in the address bar and press Enter. You should see something like the following:

images

If you type “Bob” in the textbox, characters “B”, “o”, and “b” are displayed seamlessly without refreshing the whole web page.

images

10.8 MySQL

 

10.8.1 Overview

MySQL is the most popular open-source relational SQL database system in the world. The MySQL database server provides a multithreaded, multiuser, and robust SQL information management environment for mission-critical, heavy-load production systems. MySQL can be used as a back end for any information management system and is accessible with almost all programming languages or script languages. A MySQL database can be hosted on any web server and is often coupled with PHP for web applications so that the information on the MySQL database can be accessed from anywhere in the world with any web client.

PHP can collect data and then send data to the MySQL database, and MySQL can in turn store the information. PHP can send a request to database and get a response from the database. PHP and MySQL combine to make web applications easier and more powerful in producing interactive and dynamic web pages on the fly. HTML can create useful and well-formatted web pages.

For example, web clients can use PHP to browse an online shopping catalog stored in a MySQL database, creating a shopping cart for clients to dynamically add or remove items to or from a shopping cart. MySQL can keep track of customer information, transaction information, and shipping and handling information.

10.8.2 Practice Lab for MySQL, PHP, and Apache

Let us practice AMP (Apache, MySQL, and PHP) in this lab. Download MySQL Community Server from http://dev.mysql.com/downloads/index. html; the current release version is MySQL 5.x.

images

Follow the instructions and choose the proper version for your operating system. Run the .msi file to install MySQL.

images

After you complete the wizard, you can launch the configuration wizard automatically.

images

Here is my MySQL configuration; you may configure it differently per your needs.

images

Continue on the MySQL Server Instance Configuration wizard.

images

Continue on the configuration with password settings.

images

Now you have completed the MySQL server configurations, and MySQL should run on your machine as a service. Next, go to

Start → All Programs → MySQL → MySQL Server 5.0 → MySQL Server Command Line Client and then type the password that you set up to log in to MySQL.

images

To let PHP work with MySQL, you need to have PHP installed as demonstrated in the previous tutorial.

In the configuration file C:phpphp.ini, uncomment the following two lines:

images

Copy the file libmysql.dll from c:php into C:windowssystem32.

Make sure that you have php_mysql.dll and php_mysqli.dll in your C:phpext directory.

Create a test.php file in Apache root folder htdocs, and add the following code to the file:

images

After you start up your Apache server and visit http://localhost/test.php, you should see a line reading “connected” in your browser. This indicates that you have linked Apache server, PHP, and MySQL successfully.

10.8.3 A Simple MySQL Application

In this section, you will create an online MYSQL application with PHP that will verify any names requested online against the names stored in a MySQL database.

First, log in to MySQL (Start→All Programs→MySQL→MySQL Server 5.0→MySQL Command Line Client).

Next, execute the following SQL commands to create a MySQL table with one name data field (string type) and insert a few data records.

images

Now, if your typed name matches any name in the table (John, Smith, Mike), it will be recognized. Otherwise, your request will be refused.

images

An unregistered user will be rejected as follows.

images

10.9 Summary

This appendix has given you many hands-on labs to practice using various open-source web servers that JavaScript and Ajax clients can make requests to and get responses from. You can see that the same JavaScript or Ajax client application can access different servers with only minor changes. You can choose any specific introduced technology to review and practice the materials that you have learned in this book.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset