mysql_drop_db
This function was deprecated in PHP 4.3.0, and it and the entire original MySQL extension was removed in PHP 7.0.0. Instead, use either the actively developed MySQLi or PDO_MySQL extensions. See also the MySQL: choosing an API guide. Alternatives to this function include:
Description
mysql_drop_db() attempts to drop (remove) an entire database from the server associated with the specified link identifier. This function is deprecated, it is preferable to use mysql_query() to issue an sql DROP DATABASE statement instead.
Parameters
The name of the database that will be deleted.
The MySQL connection. If the link identifier is not specified, the last link opened by mysql_connect() is assumed. If no such link is found, it will try to create one as if mysql_connect() had been called with no arguments. If no connection is found or established, an E_WARNING level error is generated.
Return Values
Returns true on success or false on failure.
Examples
Example #1 mysql_drop_db() alternative example
$link = mysql_connect ( ‘localhost’ , ‘mysql_user’ , ‘mysql_password’ );
if (! $link ) die( ‘Could not connect: ‘ . mysql_error ());
>
?php
$sql = ‘DROP DATABASE my_db’ ;
if ( mysql_query ( $sql , $link )) echo «Database my_db was successfully dropped\n» ;
> else echo ‘Error dropping database: ‘ . mysql_error () . «\n» ;
>
?>
Notes
This function will not be available if the MySQL extension was built against a MySQL 4.x client library.
Note:
For backward compatibility, the following deprecated alias may be used: mysql_dropdb()
See Also
- MySQL Functions
- mysql_affected_rows
- mysql_client_encoding
- mysql_close
- mysql_connect
- mysql_create_db
- mysql_data_seek
- mysql_db_name
- mysql_db_query
- mysql_drop_db
- mysql_errno
- mysql_error
- mysql_escape_string
- mysql_fetch_array
- mysql_fetch_assoc
- mysql_fetch_field
- mysql_fetch_lengths
- mysql_fetch_object
- mysql_fetch_row
- mysql_field_flags
- mysql_field_len
- mysql_field_name
- mysql_field_seek
- mysql_field_table
- mysql_field_type
- mysql_free_result
- mysql_get_client_info
- mysql_get_host_info
- mysql_get_proto_info
- mysql_get_server_info
- mysql_info
- mysql_insert_id
- mysql_list_dbs
- mysql_list_fields
- mysql_list_processes
- mysql_list_tables
- mysql_num_fields
- mysql_num_rows
- mysql_pconnect
- mysql_ping
- mysql_query
- mysql_real_escape_string
- mysql_result
- mysql_select_db
- mysql_set_charset
- mysql_stat
- mysql_tablename
- mysql_thread_id
- mysql_unbuffered_query
MySQLi — Drop Database
You would need special privileges to create or to delete a MySQL database. So, assuming you have access to the root user, you can create any database using the mysql mysqladmin binary.
Be careful while deleting any database because you will lose your all the data available in your database.
Here is an example to delete a database(TUTORIALS) created in the previous chapter −
[root@host]# mysqladmin -u root -p drop TUTORIALS Enter password:******
This will give you a warning and it will confirm if you really want to delete this database or not.
Dropping the database is potentially a very bad thing to do. Any data stored in the database will be destroyed. Do you really want to drop the 'TUTORIALS' database [y/N] y Database "TUTORIALS" dropped
Drop Database using PHP Script
PHP uses mysqli query() or mysql_query() function to drop a MySQL database. This function takes two parameters and returns TRUE on success or FALSE on failure.
Syntax
Required — SQL query to drop a MySQL database.
Optional — Either the constant MYSQLI_USE_RESULT or MYSQLI_STORE_RESULT depending on the desired behavior. By default, MYSQLI_STORE_RESULT is used.
Example
Try the following example to drop a database −
Copy and paste the following example as mysql_example.php −
connect_errno ) < printf("Connect failed: %s
", $mysqli->connect_error); exit(); > printf('Connected successfully.
'); if ($mysqli->query("Drop DATABASE TUTORIALS")) < printf("Database TUTORIALS dropped successfully.
"); > if ($mysqli->errno) < printf("Could not drop database: %s
", $mysqli->error); > $mysqli->close(); ?>Output
Access the mysql_example.php deployed on apache web server and verify the output.
Connected successfully. Database TUTORIALS dropped successfully.
mysql_drop_db
This function was deprecated in PHP 4.3.0, and it and the entire original MySQL extension was removed in PHP 7.0.0. Instead, use either the actively developed MySQLi or PDO_MySQL extensions. See also the MySQL: choosing an API guide. Alternatives to this function include:
Description
mysql_drop_db() attempts to drop (remove) an entire database from the server associated with the specified link identifier. This function is deprecated, it is preferable to use mysql_query() to issue an sql DROP DATABASE statement instead.
Parameters
The name of the database that will be deleted.
The MySQL connection. If the link identifier is not specified, the last link opened by mysql_connect() is assumed. If no such link is found, it will try to create one as if mysql_connect() had been called with no arguments. If no connection is found or established, an E_WARNING level error is generated.
Return Values
Returns true on success or false on failure.
Examples
Example #1 mysql_drop_db() alternative example
$link = mysql_connect ( ‘localhost’ , ‘mysql_user’ , ‘mysql_password’ );
if (! $link ) die( ‘Could not connect: ‘ . mysql_error ());
>?php
$sql = ‘DROP DATABASE my_db’ ;
if ( mysql_query ( $sql , $link )) echo «Database my_db was successfully dropped\n» ;
> else echo ‘Error dropping database: ‘ . mysql_error () . «\n» ;
>
?>Notes
This function will not be available if the MySQL extension was built against a MySQL 4.x client library.
Note:
For backward compatibility, the following deprecated alias may be used: mysql_dropdb()
See Also
User Contributed Notes
- MySQL Functions
- mysql_affected_rows
- mysql_client_encoding
- mysql_close
- mysql_connect
- mysql_create_db
- mysql_data_seek
- mysql_db_name
- mysql_db_query
- mysql_drop_db
- mysql_errno
- mysql_error
- mysql_escape_string
- mysql_fetch_array
- mysql_fetch_assoc
- mysql_fetch_field
- mysql_fetch_lengths
- mysql_fetch_object
- mysql_fetch_row
- mysql_field_flags
- mysql_field_len
- mysql_field_name
- mysql_field_seek
- mysql_field_table
- mysql_field_type
- mysql_free_result
- mysql_get_client_info
- mysql_get_host_info
- mysql_get_proto_info
- mysql_get_server_info
- mysql_info
- mysql_insert_id
- mysql_list_dbs
- mysql_list_fields
- mysql_list_processes
- mysql_list_tables
- mysql_num_fields
- mysql_num_rows
- mysql_pconnect
- mysql_ping
- mysql_query
- mysql_real_escape_string
- mysql_result
- mysql_select_db
- mysql_set_charset
- mysql_stat
- mysql_tablename
- mysql_thread_id
- mysql_unbuffered_query
Blog
You would need special privileges to create or to delete a MySQL database. So, assuming you have access to the root user, you can create any database using the mysql mysqladmin binary.
Be careful while deleting any database because you will lose your all the data available in your database.
Here is an example to delete a database(ADGLOB) created in the previous chapter −
[root@host]# mysqladmin -u root -p drop ADGLOB Enter password:******
This will give you a warning and it will confirm if you really want to delete this database or not.
Dropping the database is potentially a very bad thing to do. Any data stored in the database will be destroyed. Do you really want to drop the 'ADGLOB' database [y/N] y Database "ADGLOB" dropped
Drop Database using PHP Script
PHP uses mysqli query() or mysql_query() function to drop a MySQL database. This function takes two parameters and returns TRUE on success or FALSE on failure.
Syntax
Sr.No. Parameter & Description 1 $sqlRequired – SQL query to drop a MySQL database. 2 $resultmodeOptional – Either the constant MYSQLI_USE_RESULT or MYSQLI_STORE_RESULT depending on the desired behavior. By default, MYSQLI_STORE_RESULT is used. Example
Try the following example to drop a database −
Copy and paste the following example as mysql_example.php −
[email protected]'; $mysqli = new mysqli($dbhost, $dbuser, $dbpass); if($mysqli->connect_errno ) < printf("Connect failed: %s
", $mysqli->connect_error); exit(); > printf('Connected successfully.
'); if ($mysqli->query("Drop DATABASE ADGLOB")) < printf("Database ADGLOB dropped successfully.
"); > if ($mysqli->errno) < printf("Could not drop database: %s
", $mysqli->error); > $mysqli->close(); ?>Output
Access the mysql_example.php deployed on apache web server and verify the output.
Connected successfully. Database ADGLOB dropped successfully.