Go Back   Random Stuff Forums > Technical > Programming

Programming Discuss any type of programming here.

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 15-08-2009, 04:18 PM
Matt's Avatar
(Offline)
Administrator
 
Join Date: Jan 2007
Location: United States - Ohio
Posts: 3,820
Matt is an unknown quantity at this point
Default [PHP] Creating a table with MySQL

Note that $host, $username, $password, and $db_name must be replaced with actual login details for a database.

if (mysql_connect($host,$username,$password)){
mysql_select_db($db_name) or die('Unable to select database');
$query = "CREATE TABLE tbl_name (id int(6) NOT NULL auto_increment,name varchar(15) NOT NULL, PRIMARY KEY (id))";
mysql_query($query);
mysql_close();
echo 'The database was configured successfully!';
}
else{
echo 'There was a problem.';
}
This code will connect to a database and then execute a query that will create a table called "tbl_name" with 2 columns called "id" and "name" respectively.
__________________
"Facts do not cease to exist because they are ignored."
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -5. The time now is 03:33 AM.

Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0
Copyright © 2006 - 2010, Rsforums.org