PHP MYSQL Datbase Driven Website Primer 1
By Clinton N. Godlesky

To use MYSQL, make sure that your website uses it. You will need 4 pieces of information. They are:

username
password:
host:
database:

un and pw are easy. The host is the physical location of the database. Sometimes they are on the same machine (localhost), other times they are remote (mysql.yoursite.com). And the database is the name of the database. Databases are like:

Database > Tables > Columns.

To do most of the programming that you want to do, you'll need to get a good hold of the MYSQL language. In it's simplest terms it's just a plain english language for getting data out of a database. MYSQL databases (actually, just about all dbs) are just like a table. They have column names, data types and data.

There are a couple of easier ways to make, edit and delete tables without knowing the command line stuff. On is to have PHPMYADMIN installed on your server. This is a program that creates an HTML GUI for the database.

Another way is to use a program. A free example is http://www.webyog.com/en/. It gets most basic database tasks done, but being free, it has it's limits.

The SQL language is easy to pick up once your start using it regularly. The first and foremost use of it is to get information out of tables. For example:

SELECT * FROM table01

That line of code will return the entire table.

SELECT = This starts a data query
* = this means all columns
FROM table01 = The table yours getting data from.

You can also make it more specific:

SELECT name, age FROM table01

This returns just the name and age from the database.

SELECT * FROM table01 WHERE age > 10

This returns all records where the age data is greater than 10.

SELECT * FROM table01 WHERE age > 10 && age < 20.

This returns all records where the age data is greater than 10 and less than 20. It would be best to try to find a starter tutorial on this, and learn this before starting to make synamic websites. Once you feel your ready (you might already be), I'll send you a PHP database connection script and 3 pieces of code that commonly use to make MYSQL queries.

There are three other query types I'll crash you on really quick here:

UPDATE A RECORD:

UPDATE table01 SET age = 50 WHERE name = 'Tom'

INSERT A RECORD

INSERT INTO table01
(id, name, age)
VALUES
('', 'George', 32)

AND, DELETE A RECORD

DELETE FROM table01 WHERE age > 50

Notice that when I use numbers, I don't have to put '' marks around it. But if you use a string (text), you have to use the quote marks. You are also recommended to put `` marks around names in some cases. A super proper way of writing that last statement would be...

DELETE FROM `table01` WHERE `age` > 50

Brain full yet?

We use these queries to get data, update data, insert data, and delete data. Most often we insert and update using a form. We take the data from the form fields and insert them into the database.