Dropping MySQL Database

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 ());
>

$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 ());
    >

    $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

Оцените статью