News:

Build a stunning handcrafted website with IT Acumens

Main Menu

Create new Database

Started by VelMurugan, Dec 16, 2008, 09:45 PM

Previous topic - Next topic

VelMurugan

Create new Database

In the next example, we are creating a database user and under that, we are creating a table visitor. The table visitor will be created with four columns: a primary key called 'id' that will be auto incremented as data is added to the table, and the remaining three columns are the character (VARCHAR) fields: 'name', 'address' and 'email'. Code-2 will help you to create the table successfully.

Code 2 :- db.php
<html>
<head>
  <title>Create Database </title>
</head>
<body>
  <p>Creating Database & table in MySQL.</p>
  <?php
   
// Connecting to MySQL
   
$link mysql_connect("mysql_host""mysql_user""mysql_password") or die("Could not connect : " mysql_error());
   print 
"Connected successfully<P>";
   
$DB "user";
   
$table "visitor";
   
$query "CREATE DATABASE $DB";
   
$result mysql_query($query) or die("ERROR while creating database".mysql_error());
   print(
"OK, database made, name of DB : $DB<br><br>");
   
mysql_select_db($DB$link);
   
$query2 "CREATE TABLE $table (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, name varchar(25), address varchar(50), email varchar(25))";
   
$result2 mysql_query($query2) or die("ERROR while creating table".mysql_error());
   print(
"OK, table made, name of table : visitor<br><br>");
  
?>

</body>
</html>


If db.php runs without any error, it generates the output as shown in Output-2.

QuoteOutput 2: db.php
Testing working of MySQL.
Connected successfully
OK, database made, name of DB: user
OK, table made, name of table : visitor

Source : Techxcel

thiruvasagamani

Dear velu
How to delete the dolumn during runtime in My SQl?
Thiruvasakamani Karnan