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
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



1.
Daniele Medri | April 16, 2007 at 9:10 am
Do you need PHP for DDL SQL?