The Wayback Machine - https://web.archive.org/web/20081210141322/http://www.webreference.com:80/programming/mySQL_and_php/

search the site  

Enter search terms:


subscribe to newsletters   WebReference.com logo   WebReference.com
dev the Web
tip archive  •   about  •   contact  •   jobs  •   sitemap


[next]

Accessing Your MySQL Database from the Web with PHP

By Luke Welling, Laura Thomson

Social Bookmark

Producer
Aquent
US-WA-Redmond

Justtechjobs.com Post A Job | Post A Resume

In this chapter, we explain how to access the Book-O-Rama database from the Web using PHP. You learn how to read from and write to the database and how to filter potentially troublesome input data.

Key topics covered in this chapter include

Show Web Database Architectures Work

In Chapter 8, "Designing Your Web Database, "we outlined how web database architectures work. Just to remind you, here are the steps:

  1. A user's web browser issues an HTTP request for a particular web page. For example, the user might have requested a search for all the books written by Michael Morgan at Book-O-Rama, using an HTML form. The search results page is called results.php.
  2. The web server receives the request for results.php, retrieves the file, and passes it to the PHP engine for processing.
  3. The PHP engine begins parsing the script. Inside the script is a command to connect to the database and execute a query (perform the search for books). PHP opens a connection to the MySQL server and sends on the appropriate query.
  4. The MySQL server receives the database query, processes it, and sends the results—a list of books—back to the PHP engine.
  5. The PHP engine finishes running the script. This usually involves formatting the query results nicely in HTML. It then returns the resulting HTML to the web server.
  6. The web server passes the HTML back to the browser, where the user can see the list of books she requested.

Now you have an existing MySQL database, so you can write the PHP code to perform the preceding steps.Begin with the search form. The code for this plain HTML form is shown in Listing 11.1.

Listing 11.1 search.html— Book-O-Rama's Database Search Page

This HTML form is reasonably straightforward. The output of this HTML is shown in Figure 11.1.

The script that will be called when the Search button is clicked is results.php. It is listed in full in Listing 11.2. Through the course of this chapter,we discuss what this script does and how it works.

Listing 11.2 results.php—This Script Retrieves Search Results from the MySQL Database and Formats Them for Display

Note that this script allows you to enter the MySQL wildcard characters % and _ (underscore). This capability can be useful for the user,but you can escape these characters if they will cause a problem for your application.

Figure 11.2 illustrates the results of using this script to perform a search.


[next]

Recent Articles

WebReference.com site name
Popular JavaScript Framework Libraries: qooxdoo and SproutCore
Getting Started with ASP.NET 3.5
Administering MySQL Databases on the Web Using PHP
internet.com site name
Secure Apache: Out, Damned Bot!
How Will Economic Downturn Affect VoIP Industry?
Sprint's Xohm Becomes 'Clear', Timetable Shifts


internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Copyright 2008 Jupitermedia Corporation All Rights Reserved.

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Whitepapers and eBooks

Microsoft Technology Overview: Virtualization for Windows
IBM IT Innovation Article: Using Software to Turn Your Business Green
Symantec Whitepaper: Converging System and Data Protection for Complete Disaster Recovery
Avaya Article: Developing Speech Grammars That Rock, Part 1: Best Practices
Intel Whitepaper: Comparing Two- and Four-Socket Platforms for Server Virtualization
IBM Solutions Brief: Go Green With IBM System xTM And Intel
HP eBook: Simplifying SQL Server Management
Go Parallel Article: PDC 2008 in Review
IBM IT Innovation Article: IT Needs More Involvement in Green Initiatives
Avaya Article: Communication-Enabled Mashups: Empowering Both Business Owners and IT
Intel Whitepaper: Building a Real-World Model to Assess Virtualization Platforms
PDF: Intel Centrino Duo Processor Technology with Intel Core2 Duo Processor
  Microsoft Article: Build and Run Virtual Machines with Hyper-V Server 2008
Go Parallel Article: Q&A; with a TBB Junkie
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
IBM eBook: The Pros and Cons of Outsourcing
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya eBook: IP Application Development - Explore Device, Media and Call Control
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Symantec Whitepaper: Comprehensive Backup and Recovery of VMware Virtual Infrastructure
MORE WHITEPAPERS, EBOOKS, AND ARTICLES

Morty Proxy This is a proxified and sanitized view of the page, visit original site.