Login

Username:

Password: 

Join us Now |  Forgot Password? | Forgot UserName?

PHP

Learn step by step



MySql Create Db/Table

Mysql_create_db() function is used to create a database.
Syntax
mysql_create_db("Demodatabase");


<?php
//the example of making MySQL database
//create.php
$continued = mysql_connect("localhost","root","admin");
if($continued){
echo("Connection is succeed");
}else{
echo("Connection is fail");
}
$make = mysql_create_db("demoDatabase");
if($make){
echo("<br><br>Database demoDatabase succeeds in making");
}else{
echo("<br><br>Database demoDatabase fails in making");
}
?>

go to your browser to http://localhost/create.php. this will show
Connection is succeed
Database demoDatabase succeeds in making


Making Table

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 syntax from database program (used MySQL) then this syntax will be operated by using of mysql_query() function.
For example, make a employee database of one office, personal data table with the field of number,name, and address.
Create a file table.php and enter following code:


<?php
//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("employee");
if($make){
echo("<br><br>Employee database succeeds in making");
}else{
echo("<br><br>Employee database fails in making");
}
$order1 = "CREATE TABLE employee
(
number int(10)AUTO_INCREMENT PRIMARY KEY,
name char(100),
address varchar(255)
)";
$make_table = mysql_db_query("employee",$order1);
if($make_table){
echo("<br><br>Table data_employee succeeds in making");
}else{
echo("<br><br>Table employee fails in making");
}
?>

after running this script this will show
connection is succeed
Employee database succeeds in making
table employee succeeds in making



Related Videos