Code has been added to clipboard!
Prepared PHP PDO Statements
Example
<?php
$host = 'host';
$user = 'user';
$pass = 'pass';
$db = 'db';
// Create connection
$conn = new mysqli($host, $user, $pass, $db);
// Check connection
if ($conn->connect_error) {
die("Failed to connect: " . $conn->connect_error);
}
// bind and prepare
$stmt = $conn->prepare("INSERT INTO users (name, surname, email) VALUES (?, ?, ?)");
$stmt->bind_param("sss", $name, $surname, $email);
// set parameters and execute
$name = "John";
$surname = "Doe";
$email = "[email protected]";
$stmt->execute();
$name = "Mary";
$surname = "Moe";
$email = "[email protected]";
$stmt->execute();
$name = "Julie";
$surname = "Dooley";
$email = "[email protected]";
$stmt->execute();
echo "Uploaded.";
$stmt->close();
$conn->close();
?>