Web Services from Awave, Inc.
Communications systems and services from Awave, Inc.
Computer & Network Systems and Services from Awave, Inc.
Video and Multimedia Systems and Services from Awave, Inc.
Consulting Services from Awave, Inc.
Contact Awave, Inc.
 

BF_logo_04_IS

PHP.net
MySQL Site
WebSite Pros

Highly Recommended!

Visit these sites where we use what we teach here:

The Edge

A commercial site where really cool tie-dye clothing is sold. Uses PHP generated links to Mal's Shopping Cart.
 

Scifisource

Directory of Science Fiction and Fantasy sites. Search and category results pages use PHP generated tables to display results.

Online PHP Resources

Zend
Their engine powers PHP. They own PHP.

PHPBuilder
Good general PHP tutorials and code library

HotScripts
Large library of PHP and other code snippets and programs

Tutorial:
Using PHP and MySQL with Fusion

© 2000-2008
Awave, Inc.

Tutorial - Get Fusion 10
dynamic web sites using PHP and MySQL

Contact the author

Lesson 3 - MySQL: Still More Basics

MySQL 5.0.45 -

This is the version we're currently using. Versions of MySQL 3.23 (at least as far back as 3.23.39) are fine for most purposes. We've updated our MySQL installations with each new release and have had no problems.

Setting up a database -

If you don't own your own web server with MySQL installed, you'll need the cooperation of your hosting company to set up your database. They will provide you with a username and password to access your MySQL database on the server.

If you're lucky, you can use a GUI interface such as Heidi SQL - MySQL GUIHeidiSQL installed on your PC to access the MySQL server and create your database and modify it. If not, your hosting company will probably recommend or provide a web-based interface.

If you install PHP and MySQL on your local development machine or one on your LAN (if you have one), you can create your database locally with HeidiSQL, export it to a text file and then import it into the live server on the web.

Designing a database -

Here, you're on you own. Hopefully, you know what you want to create for your own web site or your client has provided something to start with. Database design is beyond the scope of these articles. (We get paid for that kind of stuff).

Later on in this tutorial, we'll work with a sample database that we've placed on our server and show you the text file (filename.sql) that was used to create it.

If you're really "feeling it" with your newfound connection with PHP, you can even write PHP scripts yourself to create, modify and drop (delete) tables in your database. We won't go there.

Database users -

You should set up two types of users for your database.

  • Your own, with full privileges to add, delete and modify stuff. I.e., an administrator account.
  • A webuser account with limited privileges. This may be limited to the ability to "select" information from your database for display on your web pages. If you want visitors to add or modify records, you can add those privileges as well.

A word about connecting to your database

When you want to 'connect' to a MySQL server, you'll need to provide three pieces of information in your PHP code:

  1. The hostname.

    This will depend on where you're connecting from. If you connect from a web page (site visitors will be doing this and you will be too if you have to use web-based administration) the host is localhost. If the database is not on the web server, it will be the hostname where the MySQL server is located. If you don't have your own MySQL server, ask your host for the correct hostname to use.
     
  2. A User Name

    Users are granted privileges by the MySQL administrator. This includes where they may access the database from (hostname or IP), as well as table permissions such as 'select', 'update', and 'delete'.
     
  3. A Password
     

Usage of these parameters with PHP will be covered in the next lesson.
 

Database Queries -

Queries are what you use to communicate with a database you've established a connection to. SQL is an abbreviation for Structured Query Language. If you've used databases before, you've probably used SQL. Even Microsoft Access™ includes a version of SQL, making it relatively easy to upgrade to using a more powerful database like Microsoft SQL Server or MySQL.

Moving data to MySQL-

Data is easy to import into MySQL. For example, you can export tables from a Microsoft Excel™ spreadsheet or Access database into a tab-delimited file and import that file into MySQL.

Tab delimited with one record per line is the default import format for MySQL, so make your life easier and use it if possible. Before you import, you must create the appropriate destination table in MySQL using the MySQL console (if you have direct access to the MySQL server) or better yet, using a tool like HeidiSQ.

Now let's learn how to connect to a MySQL database using PHP.

Lesson 4 - DB connection with PHP

Last Updated: 01/27/08

allwebmenus - Cross platform DHTML!