Thursday, May 24, 2012

 

Create Database & Table

Create Database

The following codes creates a database called "my_database":
mysql username is root no password added


<?php

$con = mysql_connect("localhost","root","");

if (!$con)
  {

  die('Could not connect: ' . mysql_error());

  }



if (mysql_query("CREATE DATABASE my_database",$con))

  {

  echo "Database created";

  }

else

  {

  echo "Error creating database: " . mysql_error();

  }



mysql_close($con);

?>


Create Table

The following example creates a table named "Biodata", with three columns. The column names will be "FirstName", "LastName" and "Age":
mysql username is root no password added


<?php

$con = mysql_connect("localhost","root","");

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }



mysql_select_db("my_database", $con);

$sql = "CREATE TABLE Biodata

(

FirstName varchar(15),

LastName varchar(15),

Age int

)";




mysql_query($sql,$con);



mysql_close($con);

?>

No comments:

Post a Comment