MYSQLI DELETE query

Delete with Where Query (without parameters ), Object Oriented Style
require "config.php";// Database connection file.
$query="DELETE FROM student WHERE class='Four'";
$connection->query($query);
echo " Records Delete ".$connection->affected_rows;

MySQLI database connection file

if($stmt=$connection->query("DELETE FROM student WHERE class='Four'")){
	$msg.= " One class deleted  <br>";
}else { 
$msg.="  Class  can't be deleted <br>" ;
} 
With Parameters by using bind_param()
<?Php
require "config.php";// Database connection
/////////////////////
$id=5;
$query="DELETE FROM student  WHERE id=?";
$stmt = $connection->prepare($query);
if ($stmt) {
$stmt->bind_param('i', $id);
$stmt->execute();
echo "Record Deleted :";
echo $stmt->affected_rows;
}else{
echo $connection->error;
}
?>
Procedural style
<?Php
require "config.php";// Database connection
/////////////////////
$id=6;
$class='Four';
$query="DELETE FROM  student  WHERE class=? AND id=?";
if ($stmt = mysqli_prepare($connection,$query)){
mysqli_stmt_bind_param($stmt, "si",$class, $id);
mysqli_stmt_execute($stmt);
echo "Record Deleted:";
echo mysqli_affected_rows($connection);
}else{
echo mysqli_error($connection);
}
?>

MySQL DELETE Query

Procedural style
<?Php
require "config.php";// Database connection
/////////////////////
$id=7;
$class='Fifth';
$query="DELETE FROM  student  WHERE class=? AND id=?";
if ($stmt = mysqli_prepare($connection,$query)){
mysqli_stmt_bind_param($stmt, "si",$class, $id);
mysqli_stmt_execute($stmt);
echo "Record Deleted:";
echo mysqli_affected_rows($connection);
}else{
echo mysqli_error($connection);
}
?>

MySQL DUMP of student table

Visitors Rating
Your Rating





Post Comment This is for short comments only. Use the forum for more discussions.




HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2019 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer