Answers for "Prepared statement parameters in php"

PHP
1

php prepared statement select

// Multiple rows:
$sql = "SELECT * FROM users WHERE id=?";
$stmt = $conn->prepare($sql); 
$stmt->bind_param("i", $id);
$stmt->execute();
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
    echo $row['name'];
}

//Single row:
$sql = "SELECT user FROM users WHERE id=?"; // SQL with parameters
$stmt = $conn->prepare($sql); 
$stmt->bind_param("i", $id);
$stmt->execute();
$result = $stmt->get_result(); // get the mysqli result
$user = $result->fetch_assoc(); // fetch data  

// Update/delete from
$sql = "UPDATE users SET rank=?, status=? WHERE id=?"; // SQL with parameters
$sql = "DELETE FROM users WHERE id=?";
$stmt = $conn->prepare($sql);

$stmt->bind_param('sss', $rank, $status, $id);
$stmt->execute();
Posted by: Guest on August-28-2020
0

php prepared statements

$stmt->bind_param("i", $data); // Type: Integer
$stmt->bind_param("d", $data); // Type: Double
$stmt->bind_param("s", $data); // Type: String
$stmt->bind_param("b", $data); // Type: Blob
Posted by: Guest on August-27-2021

Code answers related to "Prepared statement parameters in php"

Browse Popular Code Answers by Language