Using MySQL and PHP - 1

Creating dynamic pages from online databases.

This section deals mainly with exploring the possibilities of combining PHP and MySQL. To check if PHP is setup to use MySQL on your server, look for a section on MySQL in the phpinfo file described earlier. The technical details of setting up MySQL on your system are covered comprehensively in various text books. See the "Source Code Books" link below for more information.

Once configured, PHP uses mysql_connect() to establish a link to the MySQL manager program on the server. mysql_select_db() then specifies which database the PHP file can access. Each database can contain numerous tables. Once connected, PHP can be used to create SQL queries - simple text strings that describe the kind of operation you require MySQL to perform on the database. You can create or drop (delete) tables, alter table structure, insert, update and delete records within a table, retrieve records, individual fields or selected fields from records that match specific criteria. Queries can be sorted in alphabetical, numerical or chronological order - depending on the table and you can also limit the total number of records matched. Queries can look for exact matches (e.g. numerical fields) or approximate matches (e.g. in a text field made up of user comments).

Webhosts vary in how to configure MySQL, most create the database for you but some will also help you to create the tables too. To learn more about creating tables using SQL (and therefore via PHP too), use the linkbar below to go to the Books section: PHP. The two larger reference books describe creating SQL tables in detail.



This is part of www.codehelp.co.uk Copyright © 1998-2004 Neil Williams
See the file about.html for copying conditions.