Reading Data from the Database
Learn how to read data from the database using PHP PDO.
In this lesson, we’ll learn about the different phases of reading data from the database. We’ll learn how to prepare queries, bind parameters, define bound values, and execute queries.
Step 1: Write a query
Write a regular select statement and instead of values, put named placeholders. For example:
$sql = "SELECT * FROM users WHERE city = :city";
Step 2: Prepare the query to execute
Prepare the query:
$query = $dbh -> prepare($sql);
Bind the parameters: ...