How to delete php database

藏色散人
Release: 2023-03-11 16:50:02
Original
3194 people have browsed it

Method to delete a php database: first create a PHP sample file; then connect to the database through "mysql_connect"; finally use SQL commands to mysql_query to delete a database.

How to delete php database

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

How to delete the php database?

Deleting a MySQL database using PHP

Deleting a database

If the database is no longer needed then it can be deleted permanently. You can delete a database using SQL commands passed to mysql_query.

Example

Try the following example to delete a database.

    <?php
    $dbhost = &#39;localhost:3036&#39;;
    $dbuser = &#39;root&#39;;
    $dbpass = &#39;rootpassword&#39;;
    $conn = mysql_connect($dbhost, $dbuser, $dbpass);
    if(! $conn )
    {
      die(&#39;Could not connect: &#39; . mysql_error());
    }
    $sql = &#39;DROP DATABASE test_db&#39;;
    $retval = mysql_query( $sql, $conn );
    if(! $retval )
    {
      die(&#39;Could not delete database db_test: &#39; . mysql_error());
    }
    echo "Database deleted successfully\n";
    mysql_close($conn);
    ?>
Copy after login

Warning: It is very dangerous to delete a database and tables. So before deleting any table or database you should make sure that everything you do is voluntary.

Delete a table

It issues a SQL command again through the mysql_query function to delete any database and data table. But be very careful when using this command because by doing so you can delete some important information on your desktop.

Try the following example to delete a table:

    <?php
    $dbhost = &#39;localhost:3036&#39;;
    $dbuser = &#39;root&#39;;
    $dbpass = &#39;rootpassword&#39;;
    $conn = mysql_connect($dbhost, $dbuser, $dbpass);
    if(! $conn )
    {
      die(&#39;Could not connect: &#39; . mysql_error());
    }
    $sql = &#39;DROP TABLE employee&#39;;
    $retval = mysql_query( $sql, $conn );
    if(! $retval )
    {
      die(&#39;Could not delete table employee: &#39; . mysql_error());
    }
    echo "Table deleted successfully\n";
    mysql_close($conn);
    ?>
Copy after login

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to delete php database. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!