PHP Tutorial





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
PHP Topics
Introduction Introduction
Syntax Syntax
Data Types Data Types
Operators Operators
Control Structures Control Structures
Functions Functions
Pre-defined Function Pre-defined Function
Calendar Functions Calendar Functions
Date and Time Date and Time
Array Functions Array Functions
Array List Array Functions List1
Array Function List Array Functions List2
Math Functions Math Functions
PHP MYSQL Functions PHP Mysql Functions
File Handling File Handling
Error Handling Error Handling
DB Size DB Size
PHP Mail PHP Mail
String Tokens String Tokens
String Functions String Functions
String Functions List String Functions List1
String Functions List2 String Functions List2
Session Functions Session Functions
Cookies Functions Cookies Functions
Form Variables Form Variables
Running PHP from JS Running PHP from JS
Array To JS Array To JS
JS Array Array to PHP
Encryption Encryption
Common Header Common Header
Forums Ask Your Doubts
Scraps More about PHP
Feedback Feedback
 




mysql_drop_db() Function in PHP


Tutorials »Php »

Topic

What is mysql_drop_db() function in PHP?
How does mysql_drop_db() works?




Explanation

The mysql_drop_db function drop or remove an entire database from the server associated with the specified link identifier.

Syntax

bool mysql_drop_db ( string database_name [, resource link_identifier])

Returns TRUE on success or FALSE on failure.

mysql_drop_db() attempts to drop (remove) specified database from the server. The database to be dropped is passed as argument inside 'mysql_drop_db' function.

Example


<?php

//Attempt to connect to the default database server
$link = mysql_connect("mysql_host", "mysql_user", "mysql_password")
or die ("Could not connect");

$result= mysql_drop_db("my_database");

if ($result) {
echo "Database my_database was successfully dropped\n";
}else {
echo 'Error dropping database: ' . mysql_error() . "\n";
}

mysql_close($link);

?>


In the above example, connection to the default database server is established. The database 'my_database' to be dropped is passed as an argument to the function 'mysql_drop_db' function. After successful execution of this function the database will be dropped or removed from the server.

This function is deprecated, it is preferable to use mysql_query() to drop the database instead of 'mysql_drop_db' function.

Example:


<?php

//Attempt to connect to the default database server
$link = mysql_connect("mysql_host", "mysql_user", "mysql_password")
or die ("Could not connect");

$qry="drop database my_database";

$result= mysql_query($qry,$link);

if ($result) {
echo "Database my_database was successfully dropped\n";
}else {
echo 'Error dropping database: ' . mysql_error() . "\n";
}

mysql_close($link);

?>



See also: mysql_query()





Other Links

web hosting