$username = $_POST['username']; $password = $_POST['password']; $stmt = $pdo->prepare("SELECT * FROM users WHERE username = ? AND password = ?"); $stmt->execute([$username, $password]); $user = $stmt->fetch(); if ( $user ) { // Login successful } else { // Login failed }
$searchTerm = $_GET['searchTerm']; $stmt = $pdo->prepare("SELECT * FROM products WHERE name LIKE ?"); $stmt->execute(['%'.$searchTerm.'%']); $products = $stmt->fetchAll();In this example, PHP DB prep is used to safely input the search term into the SQL query without fear of SQL injection attacks. Overall, PHP DB prep is a package library that enables secure database query preparation and execution by automatically escaping input data, leading to safer web applications.