Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 2
Joined: Sun Mar 11, 2018 10:12 pm

Mon Mar 12, 2018 1:03 am


How do I apply DROP TABLE in my code?

<?php header("location: http://webbred2.utb.hb.se/~s163007/uppgift-read.php"); ?>

$servername = "localhost";
$username = "*****";
$password = "****";
$dbname = "*****";

$sql = "INSERT INTO Book(book_id, author, title)
VALUES ('author', 'title')";
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
echo "Database connected successfully. <br />";


catch(PDOException $e){
echo "Connection failed: " . $e->getMessage();


I ant to delete table book

php-forum Active User
php-forum Active User
Posts: 483
Joined: Fri Apr 01, 2016 2:18 am

Mon Mar 12, 2018 1:59 am

just implement it as a regular query.

New php-forum User
New php-forum User
Posts: 14
Joined: Thu Aug 17, 2017 3:37 am

Tue Mar 13, 2018 4:50 am

Why would you want to drop a table during the [normal] running of your application>
During an upgrade, maybe, but not whilst it's "just working".

Think about what would happen if you did.
One user does whatever it is that drops the table, and the other hundred or so users suddenly gets a huge error message saying that the table doesn't exist!

Or did you mean that you wanted to delete a particular book from the Book table?

Code: Select all

$sql = 'DELETE FROM Book WHERE book_id = ?' ; 
Phill W.

Post Reply