mysql_drop_db() Function in PHP
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.
Syntaxbool 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 droppedn"; }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 droppedn"; }else { echo 'Error dropping database: ' . mysql_error() . "n"; } mysql_close($link); ?> |
See also: mysql_query()