phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


PHP MySQL: Making Table

Tag: mysql, database, table   Category: PHP Database
post: 28 Feb 2008 read: 1,412


php mysql basic step by step tutorial - part 3: PHP do not provide the special function of making tables with its fields. So in order to make the data table, it stills use the sintaks from database program (used MySQL) then this sintaks will be operated by using of mysql_query() function.

For example, make a employees database of one office, personal data table with the field of employees number, employees name, and employees address.

Create a file named create_table.php within www. Enter following code:


<?
//the example of making MySQL database table
//create_table.php
$continued = mysql_connect("localhost","root","admin");
if($continued){
	echo("Connection is succeed");
}else{
	echo("Connection is fail");
}
$make = mysql_create_db("employees");
if($make){
	echo("<br><br>Employees database succeeds in making");
}else{
	echo("<br><br>Employees database fails in making");
}
$order1 = "CREATE TABLE data_employees
	(
		employees_number int(10)AUTO_INCREMENT PRIMARY KEY,
		name char(100),
		address varchar(255)
	)";
$make_table = mysql_db_query("employees",$order1);
if($make_table){
	echo("<br><br>Table data_employees succeeds in making");
}else{
	echo("<br><br>Table data_employees fails in making");
}
?>

Point your browser to http://localhost/create_table.php. May you get like this:

php mysql create table

If you see at phpmyadmin, you will get like this:

php mysql create table phpmyadmin


Series this article:
PHP MySQL: Connecting to Database Use mysql_connect()
PHP MySQL: Making Database Use mysql_create_db()
PHP MySQL: Making Table
PHP MySQL: The Data Type of Field
PHP MySQL: Char and Varchar Data Type
PHP MySQL: Data Type of Date
PHP MySQL: MySQL Syntax Orders
PHP MySQL: Inserting Data
PHP MySQL: Creating Form Insert Data
PHP MySQL: Display Data
PHP MySQL: mysql_fetch_row() Function
PHP MySQL: mysql_fetch_array() Function
PHP MySQL: Editing data
PHP MySQL: Deleting data
PHP MySQL: Adding Field Table
PHP MySQL: Editing Field Table
PHP MySQL: Deleting Field Table

| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Chart: How to Build Cool Animation Real Time Chart
Joomla: Fast Road to Understand Component Programming
Email: Send Attachement Mail
mod_rewrite - Part 1: create your "fantasy" URL

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


615
posting