Change language

PHP MySQL Delete Query

| |
Syntax:
The main syntax of a delete request - Let’s take a look at the following table" Data "with four columns" ID "," FirstName "," LastName "and" Age ". You can use the following code to delete a record of person ID 201 from the Data table.Delete a query using a procedural method: php $ link = mysql i_connect ("localhost", "root", "", "Mydb");  
if ($link === false) { die ("ERROR: Could not connect.". mysqli_connect_error()); } $ sql = "DELETE FROM Data WHERE ID = 201 " ; if (mysqli_query ($link, $sql)) { echo "Record was deleted successfully."; }
else { echo "ERROR: Could not be able to execute $sql." . mysqli_error ($link); }
mysqli_close ($link);
?>
Output: Table after update - Web browser output: Delete request using object-oriented method: php $ mysqli = new mysqli ("localhost", "root", " "," Mydb ");  
if ($mysqli === false) { die ("ERROR: Could not connect.". $mysqli-> connect_error); }  
$sql = "DELETE FROM Data WHERE ID = 201";
if ($mysqli-> query ($sql) === true) { echo" Record was deleted successfully. "; } else { echo "ERROR: Could not be able to execute $sql." . $mysqli-> error; }  
$mysqli-> close();
?>
Output: Table after update - Web browser output: Delete request using PDO method: php try { $ pdo = new PDO (" mysql: host = localhost ; dbname = Mydb "," root "," "); $pdo-> setAttribute (PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { die ("ERROR: Could not connect.". $e-> getMessage()); }  
try { $sql = "DELETE FROM Data WHERE ID = 201"; $pdo-> exec ($sql); echo "Record was deleted successfully. "; } catch (PDOException $e) { die ("ERROR: Could not be able to execute $sql." . $e-> getMessage()); }
unset ($pdo);
?>
Output: Table after update - Web browser output:

PHP MySQL Delete Query __del__: Questions

PHP MySQL Delete Query __delete__: Questions

Shop

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Best laptop for Zoom

$499

Best laptop for Minecraft

$590

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method