$servername = "localhost"; $username = "username"; $password = "password"; $dbname = "myDB"; // Create connection $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } echo "Connected successfully";
$stmt = $conn->prepare("SELECT * FROM users WHERE email = :email"); $stmt->bindParam(':email', $email); $stmt->execute(); $result = $stmt->fetchAll(PDO::FETCH_ASSOC); foreach($result as $row){ echo $row['name'] . "This PHP code queries a database using PDO prepared statements. The bindParam() function binds the :email parameter to the $email variable, and the execute() function runs the prepared statement. The fetchAll() function retrieves all rows of the result set, and the foreach loop prints out the names of each row. Overall, PDO is a powerful and popular package library for PHP database development that enables efficient and secure database management.
"; }