1. Home
  2. Computing & Technology
  3. PHP / MySQL

PHP MySQL Tutorial

By Angela Bradley, About.com

4 of 5

Create Tables

Following this same structure, we can connect to a database and create new tables. At the end we will print a line, so we know that it is done executing:

<?php
// Connects to your Database
mysql_connect("your.hostaddress.com", "username", "password") or die(mysql_error());
mysql_select_db("Database_Name") or die(mysql_error());
mysql_query("CREATE TABLE tablename ( name VARCHAR(30),
age INT, car VARCHAR(30))");

Print "Your table has been created";
?>

I find this method is often used when installing a PHP program someone else has written. Often an install file includes a way for the user to update the MySQL database from the browser. This allows people less familiar with the code to install the program more easily.

Explore PHP / MySQL
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. PHP / MySQL
  4. PHP with MySQL
  5. PHP MySQL - PHP MySQL Tutorial - Create Table

©2009 About.com, a part of The New York Times Company.

All rights reserved.