Create Table MySQL

April 16, 2007

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.

Entry Filed under: mysql. .

1 Comment Add your own

Leave a Comment

Required

Required, hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed


Spam Blocked

Flickr Photos

Freeze

*

Cabo Negro

More Photos

Blogroll

Recent Posts

Recent Comments

Brightshore Miami on Convert em,px,pt and % in…
zolofth on Mozilla Addons and IE Addons f…
xx on validating textarea using…
jafar on Top 50 Govt Engineering C…
jafar on Top 50 Govt Engineering C…

Pages

Top Clicks

Top Posts

Blog Stats