PHP and MySQL For Dummies by Janet Valade

PHP and MySQL For Dummies by Janet Valade

Author:Janet Valade
Language: eng
Format: epub, pdf
Publisher: Wiley
Published: 2010-03-09T05:00:00+00:00


Chapter 8

Data In, Data Out

In This Chapter

Connecting to the database

Getting information from the database

Using HTML forms with PHP

Getting data from an HTML form

Processing the information that users type into HTML forms

Storing data in the database

Using functions to move data into and out of the database

PHP and MySQL work well together. This dynamic partnership is what makes PHP and MySQL so attractive for Web database application development. Whether you have a database full of information that you want to make available to users (such as a product catalog) or a database waiting to be filled up by users (for example, a membership database), PHP and MySQL work together to implement your application.

One of PHP’s strongest features is its ability to interact with databases. It provides functions that make communicating with MySQL extremely simple. You use PHP functions to send SQL queries to the database. You don’t need to know the details of communicating with MySQL; PHP handles the details. You only need to know the SQL queries and how to use the PHP functions.

In previous chapters, I describe the tools that you use to build your Web database application. You find out how to build SQL queries in Chapter 4 and how to construct and use the building blocks of the PHP language in Chapters 6 and 7. In this chapter, you find out how to use these tools for the specific tasks that a Web database application needs to perform.

PHP and MySQL Functions

You use built-in PHP functions to interact with MySQL. These functions connect to the MySQL server, select the correct database, send SQL queries, and perform other communication with MySQL databases. You don’t need to know the details of interacting with the database because PHP handles all the details. You need to know only how to use the functions.

As of PHP 5, PHP offers two sets of functions for communicating with MySQL: one set of functions (the mysqli functions) for use with MySQL 4.1 or later and another set of functions (the mysql functions) for use with MySQL 4.0 and earlier versions. Most Web hosts offer MySQL 5.0 or 5.1. If they offer only earlier versions of MySQL, you might want to contact the folks in tech support to see when they’re going to provide a more recent version of MySQL.

If you’re using PHP 5 on your Web host, the mysqli functions should be available. If only the mysql functions are available, contact tech support at your Web host and ask someone to activate the mysqli functions. There is no reason to continue to use mysql functions when using PHP 5 or later.

On your local computer, if you installed your software using XAMPP, as suggested in this book and described in Appendix A, you have PHP 5 running on your computer and both the mysql and mysqli functions are available. You can change to PHP 4 using the XAMPP main page, but there should be no reason to do this. Unless you need to work on an



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.