Skip to content

TechXcel.com - provides technical excellence...

Narrow screen resolution Wide screen resolution Increase font size Decrease font size Default font size default color orange color green color
You are here: Home arrow Articles arrow PHP arrow PHP Database Integration With MySQL
PHP Database Integration With MySQL PDF Print E-mail
(7 votes)
The Article - php
Written by Chetankumar Akarte   
Wednesday, 07 March 2007
Article Index
PHP Database Integration With MySQL
Create New Database
Select MySQl Database
Adding Data to Table
Retrive Data
Error Handing
Source Code

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.

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



Last Updated ( Tuesday, 13 March 2007 )
 

Who's Online

User Login

PayPal Donation

Enter Amount:

Syndicate

TechXcel's Friends

Tutorials Garden
Wicolorz
pixel2life

Text Link Add

Statistics

Members: 271
News: 60
Web Links: 6
Visitors: 301001

Google Seach

Google AdSense

TechXcel Referrals

TechXcel's Sponcer...