Get PHP MySQL Tools
at
iPage Affordable Web Hosting only $3.50/mo

PHP MySQL
Interactive Website Design

Creating a Table

A database will contain a variable number of tables of data which are arranged in columns and rows. Each table is supplied with a unique name upon creation. Variables contained within the table are supplied with definitions for type and length.

CREATE TABLE birthdays( id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),
name VARCHAR(30),
birthday VARCHAR(7));

In the example shown above, we create a table named birthdays.

The table contains 3 columns:
a primary key field called id which will be automatically incremented each time a record is added.
a name field which will contain a variable number of characters up to 30
a birthday field which will contain a variable number of characters up to 7.

<?
$db="mydatabase";
$link = mysql_connect("localhost");
if (! $link)
die("Couldn't connect to MySQL");
mysql_select_db($db , $link)
or die("Select DB Error: ".mysql_error());

/* create table */
mysql_query(
"CREATE TABLE birthdays(
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),
name VARCHAR(30),
birthday VARCHAR(7))") or die(mysql_error());

mysql_close($link);
?>

In the example code shown above, before the table can be created, the database must first be selected using the code:
mysql_select_db($db , $link)

Download the Scripts

The Birthdays Database management files can be downloaded in a zip file. The package contains an integrated db management system, with a simple interface. This Instruction file is included in the download.
Download birthdays_db.zip

MySQL Tutorial

To extend your knowledge of MySQL study the Docs and Tutorials at the official MySQL website. MYSQL.com