2. How to create database
using phpmyadmin
Goto : http://localhost/phpmyadmin in browser
In Create New Database field: put the name of your
Database (ie: my_db)
Click on Go button
Now your database is ready and you can create
tables
3. How to create table using
phpmyadmin
Click on your database name
Put the name of table in table field
Put the number of fields in your database
Click on go
Now you can put the length, type etc to each feild
4. How to connect php file
with database
Before you can access data in a database, you must
create a connection to the database.
In PHP, this is done with the mysql_connect()
function.
Syntax:
mysql_connect(servername,username,password);
5. Example
<?php $con = mysql_connect("localhost",“root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
Else echo” your are connect with database”;
mysql_close($con);
?>
6. Insert Data into tables
<?php
$con = mysql_connect("localhost",“root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("my_db", $con);
mysql_query("INSERT INTO Persons (FirstName, LastName,
Age) VALUES ('Peter', 'Griffin', '35')");
mysql_query("INSERT INTO Persons (FirstName, LastName,
Age) VALUES ('Glenn', 'Quagmire', '33')");
mysql_close($con);
?>
7. Delete Record
<?php
$con = mysql_connect("localhost",“root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("my_db", $con);
mysql_query("DELETE FROM Person WHERE
LastName='Griffin'");
mysql_close($con);
?>
8. Update record
<?php
$con = mysql_connect("localhost",“root",""); if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("my_db", $con);
mysql_query("UPDATE Person SET Age = '36' WHERE
FirstName = 'Peter' AND LastName = 'Griffin'");
mysql_close($con);
?>