Creating MySQL Tables with PHP
3 posts
Page 1 of 1
Okay, so in the tutorial I will teach you how to set up a piece of code that inserts Tables and Data into a MySQL database
This could be used with an Installer for a piece of Web Software ect.
It's pretty basic stuff really.
We start off by telling PHP the details to your SQL database
If you wish for your table to have a primary ID key within it, this is usually used when making a member table or post table ect, we would specify this code:
Now we can begin specifying all the tables we want to be created, and then close the parameters
Happy Programming!
This could be used with an Installer for a piece of Web Software ect.
It's pretty basic stuff really.
We start off by telling PHP the details to your SQL database
Code: Select all
After this we open our parameters and tell it to create a new table
<?php
//Host | Database User | Database Password
mysql_connect("localhost", "", "") or die(mysql_error());
//Database Name
mysql_select_db("") or die(mysql_error());
mysql_query
Code: Select all
You would replace 'name' with the name you wish to call your table.("CREATE TABLE name")
If you wish for your table to have a primary ID key within it, this is usually used when making a member table or post table ect, we would specify this code:
Code: Select all
The automatically put's the ID in every new record entered into the databaseid INT NOT NULL AUTO_INCREMENT,
Now we can begin specifying all the tables we want to be created, and then close the parameters
Code: Select all
Obviously not everything works the first time, so its important that we have a die statement at the end of ever SQL queryname VARCHAR(900),
description VARCHAR(900),
logo VARCHAR(900),
keywords VARCHAR(900))")
Code: Select all
Or if it was successful output a success message
or die(mysql_error());
Code: Select all
You should now have code similar too
echo "System Information Table Created";
?>
Code: Select all
Save the code to a .php file, upload it to a server and execute it!<?php
mysql_query("CREATE TABLE info(
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),
name VARCHAR(900),
description VARCHAR(900),
logo VARCHAR(900),
keywords VARCHAR(900))")
or die(mysql_error());
echo "System Information Table Created";
?>
Happy Programming!
Back Aegean sorry not been on i.v just been moving.
Was this posted before?
Last edited by mandai on Thu Jan 12, 2012 11:13 pm, edited 1 time in total.
wrighty please give credit to the original coders who gave this out.
Rocky
Rocky
3 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023