Database Connectivity Using PHP
Database Connectivity Using PHP
mysql_connect(“severname”,username,password);
(a) servername
(b) username
(c) password
It is used to specify the password given with
the username in our case it is blank.
e.g.
$con =
mysql_connect("localhost","root","");
mysql_select_db("databasename",connectionobject);
e.g.
mysql_select_db("my_db", $con);
mysql_query("sql query");
e.g.
$result = mysql_query("SELECT *
FROM person");
e.g.
$row =
mysql_fetch_array($result)
$row["fieldname"];
e.g.
<html>
<head>
<title>Using Database Connectivity</title>
</head>
<body bgcolor=cyan>
<?php
//connect to the server
$con = mysql_connect("localhost","root","");
while($row=mysql_fetch_array($result))
{
echo "Employee Id :".$row["empid"]."<br>";
echo "Employee Name :".
$row["ename"]."<br>";
echo "Employee Salary :".
$row["esalary"]."<br><br>";
}
?>
</body>
</html>