Our examples made use of two of the main classes in PHP Data Objects: the PDO
class, which is used to create a connection and issue queries, and the PDOStatement
class, which we use to loop through the result set. We will look at the first of these classes in later chapters. Here, we will examine the PDOStatement
class to see what other ways of traversing the result set that it has to offer.
As we already know, instances of the PDOStatement
class are returned from the call to PDO::query()
method. The main purpose of this class is to provide an interface to the result set. In fact, we have already used its most important method to iterate over the result set. We only looked at one fetch style (or mode of the returned row), but PDO offers several styles. This class can also provide additional information about a result set, such as the number of rows and columns, and fetch the whole result set into a two-dimensional array.
Let's begin by looking at some different...