-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path70. MySQLiProPreUpdate.php
More file actions
45 lines (34 loc) · 1.14 KB
/
70. MySQLiProPreUpdate.php
File metadata and controls
45 lines (34 loc) · 1.14 KB
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
<?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>";
// Update SQL statement
$sql = "UPDATE student SET name = ?, roll = ?, address = ? WHERE id= ?";
// Prepare Statement
$result = mysqli_prepare($conn, $sql);
if($result) {
// Bind Variables to Prepare Statement as Parameters
mysqli_stmt_bind_param($result, 'sisi', $name, $roll, $address, $id);
// Variables and values
$name = "Redmi";
$roll = 200;
$address = "Mumbai";
$id = 1;
// Execute Prepared Statement
mysqli_stmt_execute($result);
echo mysqli_stmt_affected_rows($result) . "Row Updated <br>" ;
}
// close prepared statement
mysqli_stmt_close($result);
// Close Connection
mysqli_close($conn);
?>