DROP TABLE

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
linneabb
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

HI!

How do I apply DROP TABLE in my code?

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

<?php
$servername = "localhost";
$username = "*****";
$password = "****";
$dbname = "*****";

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


}

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

</body>
</html>

I ant to delete table book

chorn
php-forum Fan User
php-forum Fan User
Posts: 559
Joined: Fri Apr 01, 2016 2:18 am

Mon Mar 12, 2018 1:59 am

just implement it as a regular query.

Phi11W
New php-forum User
New php-forum User
Posts: 17
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 = ?' ; 
Regards,
Phill W.

Post Reply