Create Table MySQL

April 16, 2007 at 4:49 am 2 comments

Before you can enter data (rows) into a table, you must first define the table by naming what kind of data it will hold (columns). We are going to do a MySQL query to create this table. In future lessons we will be using this table, so be sure to enter this query correctly!

PHP & MySQL Code:

<?php
// Make a MySQL Connection
mysql_connect("localhost", "admin", "1admin") or die(mysql_error());
mysql_select_db("test") or die(mysql_error());

// Create a MySQL table in the selected database
mysql_query("CREATE TABLE example(
id INT NOT NULL AUTO_INCREMENT, 
PRIMARY KEY(id),
 name VARCHAR(30), 
 age INT)")
 or die(mysql_error());  

echo "Table Created!";

?>

Display:

Table Created!

Wow! That’s a lot of code all at once! Let’s get down in the dirt and figure this stuff out. We will be going through the code line by line.

Advertisements

Entry filed under: mysql.

MySQL Connect Inserting Data Into Your Table

2 Comments Add your own

  • 1. Daniele Medri  |  April 16, 2007 at 9:10 am

    Do you need PHP for DDL SQL? 🙂

    Reply
  • 2. Benito  |  May 24, 2013 at 1:38 pm

    I am now not sure the place you are getting your info, but good topic. I needs to spend a while finding out more or understanding more. Thank you for magnificent info I used to be on the lookout for this information for my mission.

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


Flickr Photos

so goddamn hot today (brescia, italy)

Past memories

Iglesia del antiguo Monasterio de Carboeiro.

More Photos

Blog Stats

  • 714,885 hits

%d bloggers like this: