$pdo = new PDO("mysql:host=localhost;dbname=example", "username", "password"); $stmt = $pdo->prepare("INSERT INTO mytable (name, email, age) VALUES (?, ?, ?)"); $name = "John Smith"; $email = "john@example.com"; $age = 30; $stmt->pexecute([$name, $email, $age]);
$pdo = new PDO("mysql:host=localhost;dbname=example", "username", "password"); $stmt = $pdo->prepare("SELECT * FROM mytable WHERE age > ?"); $age = 30; $stmt->pexecute([$age]); $result = $stmt->fetchAll(PDO::FETCH_ASSOC);Here, we prepare an SQL SELECT statement with a placeholder for age, bind a variable to that placeholder using pexecute(), and use fetchAll() to fetch all the rows that match the age criteria from the database. The pexecute() function is part of the PHP PDO library, which is built into PHP and doesn't require any external packages or libraries.