Kalaimaan

Doing simple things to make great life

Posts Tagged ‘MySql Connectivity’

PHP with MySql Connectivity and Datamanipulation

Posted by kalaimaan on February 3, 2009

PHP with MySql Connectivity and Datamanipulation

The following example is describe the details of insert delete and view the datas from my sql using PHP script

Example:

<html>
<body>

<table width=”100%” border=”2″>
<tr><td><center>Welcome to PHP script</center></td></tr>
</table>

<?php

$Server = “localhost”;
$Username =”root”;
$Password = “admin”;

mysql_connect($Server,$Username, $Password) or die(mysql_error());
echo “Connected to MySQL<br />”;
mysql_select_db(“emp”) or die(mysql_error());
echo “Connected to Database<br>”;

printData();
insertData();
deleteData();

// insert details to the selected mysql table
// delete details to the selected mysql table
function printData()
{
// Select Details from the table
$result = mysql_query(“SELECT * FROM empm”) or die(mysql_error());

echo “<table border=’1′ width=’50%’>”;
echo “<tr> <th>Id</th> <th>Name </th> <th>Phone No. </th> </tr>”;

while($row = mysql_fetch_array( $result ))
{
echo “<tr><td>”;
echo $row[’empid’];
echo “</td><td>”;
echo $row[‘name’];
echo “</td><td>”;
echo $row[‘pno’];
echo “</td>”;
echo “</tr>”;
}

echo “</table>”;
}

function insertData()
{
// Insert a row of information into the table “example”
mysql_query(“INSERT INTO empm (empid,name,pno) VALUES(‘0006′,’Sri’,’98418′ ) “) or die(mysql_error());
echo “Data Inserted!”;
printData();
}

function deleteData()
{
mysql_query(“Delete from empm where empid =’0006′”) or die(mysql_error());
echo “Data Deleted!”;
printData();
}

?>

</body>

</html>

Screen Shot:screen1

Posted in PHP | Tagged: , , , , , , | Leave a Comment »