Thursday, May 24, 2012


Drop Database & Table

Drop Database

The following codes drop a database called "my_database": mysql username is root no password added

<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully<br />';
$sql = 'DROP DATABASE my_database';
$retval = mysql_query( $sql, $conn );
if(! $retval ) {
die('Could not delete database: ' . mysql_error());
} echo "Database my_database deleted successfully\n";
mysql_close($conn);
?>

Drop Table

The following example drop a table named "Biodata" mysql username is root no password added

<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully<br />';
$sql = "DROP TABLE biodata";
mysql_select_db( 'my_database' );
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not delete table: ' . mysql_error());
}
echo "Table deleted successfully\n";
mysql_close($conn);
?>

No comments:

Post a Comment