-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path68. MySQLiProPrepDelete.php
More file actions
42 lines (31 loc) · 1020 Bytes
/
68. MySQLiProPrepDelete.php
File metadata and controls
42 lines (31 loc) · 1020 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
$db_host = "localhost";
$db_user = "root";
$db_password = "";
$db_name = "test_db";
// Create connection
$conn = mysqli_connect($db_host, $db_user, $db_password, $db_name);
// Check connection
if (!$conn) {
// die("Connection failed");
die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully <hr>";
// DELETE SQL statement
$sql = "DELETE FROM student WHERE id= ?";
// Prepare Statement
$result = mysqli_prepare($conn, $sql);
if($result) {
// Bind Variables to Prepare Statement as Parameters
mysqli_stmt_bind_param($result, 'i', $id);
// Variables and values
$id = 21;
// Execute Prepared Statement
mysqli_stmt_execute($result);
echo mysqli_stmt_affected_rows($result) . "Row Deleted <br>" ;
}
// close prepared statement
mysqli_stmt_close($result);
// Close Connection
mysqli_close($conn);
?>