Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals

How to delete records?

1) Write the delete statement:
[code language=”php”]
$sql = "DELETE FROM `users` WHERE `id`=:id";
[/code]

2) Prepare the query:
[code language=”php”]
$query = $dbh -> prepare($sql);
[/code]

3) Bind the parameters:
[code language=”php”]
$query -> bindParam(‘:id’, $id, PDO::PARAM_INT);
[/code]

4) Define the bound values:
[code language=”php”]
$id = 1;
[/code]

5) Execute the query:
[code language=”php”]
$query -> execute();
[/code]

6) Check that the query has been performed and that the records have been successfully deleted from the database.
[code language=”php”]
if($query -> rowCount() > 0)
{
$count = $query -> rowCount();
echo $count . " rows were affected.";
}
else
{
echo "No affected rows.";
}
[/code]

All code together now:
[code language=”php”]
$sql = "DELETE FROM `users` WHERE `id`=:id";
$query = $dbh -> prepare($sql);
$query -> bindParam(‘:id’, $id, PDO::PARAM_INT);
$id = 1;
$query -> execute();
if($query -> rowCount() > 0)
{
$count = $query -> rowCount();
echo $count . " rows were affected.";
}
else
{
echo "No affected rows.";
}
[/code]

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments

Certification Courses

DevOpsSchool has introduced a series of professional certification courses designed to enhance your skills and expertise in cutting-edge technologies and methodologies. Whether you are aiming to excel in development, security, or operations, these certifications provide a comprehensive learning experience. Explore the following programs:

DevOps Certification, SRE Certification, and DevSecOps Certification by DevOpsSchool

Explore our DevOps Certification, SRE Certification, and DevSecOps Certification programs at DevOpsSchool. Gain the expertise needed to excel in your career with hands-on training and globally recognized certifications.

0
Would love your thoughts, please comment.x
()
x