PHP Knowledge Base
Example of a PHP PDO SELECT Query
Selecting multiple rows
<?php $servername = "localhost"; $username = "username"; $password = "password"; $dbname = "movies"; $whichTable = "movie_genres"; $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $sql = "SELECT * FROM $whichTable"; $stmt = $conn->query($sql); while ($row = $stmt->fetch()) { $name__mysql = $row['genre_name__mysql']; $name__html = $row['genre_name__html']; echo "MySQL name = $name__mysql; HTML name = $name__html<br>\n"; } ?>
Note:
Change $username, $password to your MySql username, password.