âš ī¸ Warning âš ī¸ Deprecated Code! This video tutorial contains outdated code.
💡 If you wish to update it, any AI assistant will update the code for you in seconds.

PDO Prepared Statements PHP Tutorial

Published : January 26, 2015   •   Last Edited : November 24, 2025   •   Author : Adam Khoury
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;
?>