PDO Prepared Statements PHP Tutorial
Learn to create PDO Prepared Statements and quickly discover its key benefits. In the very next video tutorial you can learn to create prepared statements using mysqli. Prepared statements work for Both the PDO and mysqli extensions in PHP.
<?php $db = new PDO('mysql:host=localhost;dbname=db_name', 'db_user', 'db_password'); // :username, :gender, :country are named placeholders in the SQL syntax below $sql = "INSERT INTO people (username, gender, country) VALUES (:username, :gender, :country)"; $stmt = $db->prepare($sql); $stmt->bindParam(':username', $username); $stmt->bindParam(':gender', $gender); $stmt->bindParam(':country', $country); $username = 'Beth'; $gender = "f"; $country = "Canada"; $stmt->execute(); $username = 'Sandeep'; $gender = "m"; $country = "India"; $stmt->execute(); echo "Prepared statements have been executed"; $db = null; ?>