1. Computing

PHP MySQL Tutorial

By , About.com Guide

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.

Related Video
How to Create a PHP Calendar
Basic PHP Syntax
  1. About.com
  2. Computing
  3. PHP / MySQL
  4. PHP with MySQL
  5. PHP MySQL - PHP MySQL Tutorial - Create Table

©2013 About.com. All rights reserved.