Working With PhpMyAdmin
Working With PhpMyAdmin :
Phpmyadmin is a tool developed in php language
for remote DB administration.
Start apache web server
and mysql db server.
Open browser and
provide the url as
before you can work
with db server our application must create a connection to the mysql db server.
1.
Mysql_connect() :
function is used for connecting to mysql db server using php.
Mysql_connect(DB
hostname.username,password);
The
above function will return a resource of
type mysql link on successful connection with db server and false on
failure.
2.
Mysql_close(): function is used for closing the connection
with mysql DB server.
Mysql_close(mysql
link);
3.
Mysql_error() : is a function used for
getting error message assosiated with the previous mysql operation ,if any.
4.
Mysql_errno() : used for getting the
error number assosiated with previous db operation ,if any.
5.
Mysql_select_db() : function used for
activating a DB present in mysql db server.
Mysql_select_db(database
name);
6.
Mysql_query() : function is used for passing an sql query
to the connected mysql db.
Mysql_query(string
query);
<?php
$con =
mysql_connect("localhost","root","");
if($con)
{
$res = mysql_query("create database
emp");
if($res)
echo "database is created!!!";
else
echo "database couldnot be created -
".mysql_error (). "--".mysql_errno ();
}
else
echo "couldnot connect to DB";
?>
OutPut:
database is created!!!
Program
to create a table with tha name of emp in employee database?
<?php
$con =
mysql_connect("localhost","root","");
mysql_select_db("emp");
$res=
mysql_query("create table emp2(empno int(10) primary key,ename
varchar(20),sal float(10,2))");
if($res)
echo "table created!!";
else
echo "error-".mysql_error ();
mysql_close($con);
?>
OuPut:
table created!!
Program to insert a new record into emp table?
<?php
$con =
mysql_connect("localhost", "root", "");
mysql_select_db("emp");
$res=
mysql_query("insert into emp2(empno,ename,sal)
values(102,'chandu',123.45),(103,'karanam',23.43)");
if($res)
echo "record
inserted-".mysql_affected_rows ();
else
echo "Error-".mysql_error ();
mysql_close($con);
?>
OutPut:
record inserted-2.
thank you for this article
ReplyDeletewant to move abroad