Fetching Data Using PDO

Fetching data using PDO

Fetching data using PDO

Fetching data using PDO

Hello today I will show you how to fetch data from MYSQL database using PDO.

But first you need to understand how to connect database using PDO Please check Learning PDO

Prepared statements  – are so useful that they are the only feature that PDO will emulate for drivers that don’t support them.

PDOStatement::fetchAll() returns an array containing all of the remaining rows in the result set. The array represents each row as either an array of column values or an object with properties corresponding to each column name. An empty array is returned if there are zero results to fetch, or FALSE on failure.

Now lets create a simple example. We will used our previous database Learning PDO

Now lets try to add some where conditions.
PDOStatement::bindValue – Binds a value to a corresponding named or question mark placeholder in the SQL statement that was used to prepare the statement.

Execute a prepared statement with named placeholders

Execute a prepared statement with question mark placeholders

For more information about PDOStatement::fetchAll()  visit here