O'Reilly logo

HTML, XHTML, & CSS All-in-One For Dummies®, 2nd Edition by Andy Harris

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 7. Connecting to a MySQL Database

In This Chapter

  • Building the connection string

  • Sending queries to a database

  • Retrieving data results

  • Formatting data output

  • Allowing user queries

  • Cleaning user-submitted data requests

Data has become the prominent feature of the Web. As you build more sophisticated sites using XHTML and CSS, you will eventually feel the need to incorporate data into your Web sites. You can do a certain amount of data work with the basic data structures built into PHP. Increasingly, Web sites turn to relational database management systems (RDBMSs) to handle their data needs. A RDBMS is a special program which accepts requests, processes data, and returns results.

Tip

This chapter assumes you have a database available and also that you have some basic knowledge of how SQL (Structured Query Language; the language of databases) works. If you're unfamiliar with these topics, please look over Book VI, which describes using data in detail.

Retrieving Data from a Database

PHP programmers frequently use MySQL as their preferred data back end for a number of good reasons:

  • MySQL is open source and free. Like PHP, MySQL is open source, so PHP and MySQL can be used together (with Apache) to build a very powerful low-cost data solution.

  • MySQL is very powerful. MySQL's capability as a data program has improved steadily, and it is now nearly as capable as commercial tools costing thousands of dollars. (And it is better than many that cost hundreds of dollars.)

  • PHP has built-in support ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required