August 23

List of fetch options in PDO

PDO

Below are the list of the fetch option available in using PDO:

Primitive fetch

  • PDO::FETCH_ASSOC
    Specifies that the fetch method shall return each row as an array indexed by column name as returned in the corresponding result set.
    If the result set contains multiple columns with the same name, PDO::FETCH_ASSOC returns only a single value per column name.
  • PDO::FETCH_NAMED
    Specifies that the fetch method shall return each row as an array indexed by column name as returned in the corresponding result set.
    If the result set contains multiple columns with the same name, PDO::FETCH_NAMED returns an array of values per column name.
  • PDO::FETCH_NUM
    Specifies that the fetch method shall return each row as an array indexed by column number as returned in the corresponding result set, starting at column 0.
  • PDO::FETCH_BOTH
    Specifies that the fetch method shall return each row as an array indexed by both column name and number as returned in the corresponding result set, starting at column 0.

Continue reading

Category: PDO | LEAVE A COMMENT
August 23

What is PDO?

pdo

PDO is the abbrevation of PHP Data Objects. It is a lightweight system or to be precise, it is rather an interface to access data from databases with PHP.

 

How to use PDO?

The PDO system consists of 3 classes: PDO, PDOStatement & PDOException.
The PDO class is responsible for maintaining the database connection doing some conection related stuff (like Transactions) and create the instances of the PDOStatement class.
The PDOStatement class is what you work with most of the time. It is handling the SQL queries and the fetching of the results.
The PDOException class is what you need for error handling.

Continue reading

Category: PDO | LEAVE A COMMENT