-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path80. MySQLiOOPPreUpdate.php
More file actions
46 lines (34 loc) · 972 Bytes
/
80. MySQLiOOPPreUpdate.php
File metadata and controls
46 lines (34 loc) · 972 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
43
44
45
46
<?php
$db_host = "localhost";
$db_user = "root";
$db_password = "";
$db_name = "test_db";
// Create Connection
$conn = new mysqli($db_host, $db_user, $db_password, $db_name);
// Check Connection
if($conn->connect_error){
die("Connection Failed");
}
echo "Connected Successfully <hr>";
// Update SQL statement
$sql = "UPDATE student SET name = ?, roll = ?, address = ? WHERE id= ?";
// Prepared Statement
$result = $conn->prepare($sql);
if($result) {
// Bind Variables to Prepared Statement as Parameters
$result->bind_param('sisi', $name, $roll, $address, $id);
// Variables and values
$name = "Redmi";
$roll = 200;
$address = "kolkata";
$id = 1;
// Execute Prepared statement
$result->execute();
// Number of row affected
echo $result->affected_rows . " Row Updated <br>" ;
}
// close prepared statement
$result->close();
// Close Connection
$conn->close();
?>