DWPD : Practical 20
Script for index.php file<?php
$con=mysql_connect('localhost','root','')or die("dd");
if($con)
{
echo "<b>MYSQL server connected</b><br><br>";
}
$sql="CREATE DATABASE SrDB";
if($query=mysql_query($sql))
{
echo "<b>Database created </b><br><br>";
}
if(mysql_select_db('SrDB',$con))
{
echo "<b>Database Connected </b><br><br>";
}
$TBL = 'CREATE TABLE `DATA` (`NAME` VARCHAR(20) NOT NULL, `AGE` INT(5) NOT NULL)';
if($query1=mysql_query($TBL))
{
echo "<b>Table 'data' created </b><br><br>";
}
$INSERT="INSERT INTO data(NAME,AGE) VALUES('SARJIL',21)";
if(mysql_query($INSERT))
{
echo "<b>Data inserted into table 'data'</b><br><br>";
}
$select="SELECT * FROM data";
$get=mysql_query($select);
while($raw=mysql_fetch_array($get))
{
echo "<b>Data Retrieved From Table 'data'</b><br><br>";
echo "name = ".$raw['NAME']."<br>";
echo "age = ".$raw['AGE']."<br><br>";
}
$drop='DROP DATABASE `srdb`';
if(mysql_query($drop))
{
echo "<b>Database Dropped</b><br><br>";
}
$close=mysql_close($con);
if($close)
{
echo "<b>Connection Closed to MYSQL server";
}
?>
Output :
Comments
Post a Comment