. Updated Daily. Editions SDA India   SDA Indonesia
BUSINESS ENTERPRISE SOLUTIONS ARCHITECTURE INFORMATION SECURITY WIRELESS & MOBILITY DATA & STORAGE DEVELOPMENT HARDWARE













News

Wednesday, 30 May 2007

Working with PHP and MySQL

 

 

Devshed carries an article by O’Reilly, which shows you how to select the database, fetch and display data, and more. This article is excerpted from Chapter nine of Learning PHP and MySQL, written by Michele Davis and Jon Phillips.

The article is explained under the following sections:

Selecting the Database

This first step shows which database to use with the mysql_select_db command. It takes two parameters: the database name and, optionally, the database connection. If you don't specify the database connection, the default will show in the connection from the last mysql_connect.

Building the SQL SELECT Query

Building a SQL query is as easy as setting a variable to the string that is your SQL query. You need to use a valid SQL query, or MySQL returns with an error when you execute the query. The variable name is used, but you can choose anything you'd like for a variable name. The SQL query in this example is SELECT * FROM books.

Executing the Query

To have the database execute the query, use the mysql_query function. It takes two parameters—the query and optionally the database link—and returns the result.

Fetching and Displaying

This section is explained under two sub sections—Fetch types and Closing the Connection

Putting it Altogether

Here the author takes all of the steps and put them into a single PHP file that is called db_test.php.

Using PEAR

The author explains that PEAR is a framework and distribution system for reusable PHP components. Actually, PEAR is a collection of add-on functionality for PHP development. There are many modules available to handle everything from session management to shopping cart functionality. Tables on PEAR Modules are given to facilitate a better understanding.

 

Read the Post

 
 
print save email comment

print

save

email

comment

 
 

Search SDA Asia

Free eNewsletter

SDA Asia Magazine Free Download
 
 
 
Copyright @ 2009 SDA Asia Magazine - All Right Reserved Privacy Policy | Terms of Use