1. About.com
  2. Computing & Technology
  3. PHP / MySQL

Discuss in my forum

PHP MySQL Tutorial

By , About.com Guide

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.

©2012 About.com. All rights reserved. 

A part of The New York Times Company.