Prepared statement in php

<?php

// Create connection
$conn = new mysqli('localhost', 'root', '', 'test');

// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// prepare and bind
$stmt = $conn->prepare("INSERT INTO test (name, email) VALUES (?, ?)");
$stmt->bind_param("ss", $name, $email);

// set parameters and execute
$name = "Saurabh";
$email = "info@www.coding4developers.com";
$stmt->execute();

$name = "Gauravg";
$email = "query@www.coding4developers.com";
$stmt->execute();

echo "New records created successfully";

$stmt->close();
$conn->close();
?>

Share This:

Leave a Reply

Your email address will not be published. Required fields are marked *