Web hosting services - CHAPTER 23 INTRODUCING PDO Retrieving Data PDO s

CHAPTER 23 INTRODUCING PDO Retrieving Data PDO s data-retrieval methodology is quite similar to that found in any of the other database extensions. In fact, if you ve used any of these extensions in the past, you ll be quite comfortable with PDO s five relevant methods. These methods are introduced in this section, and are accompanied by examples where practical. All of the methods introduced in this section are part of the PDOStatement class, which is returned by several of the methods introduced in the previous section. columnCount() integer PDOStatement::columnCount() The columnCount() method returns the total number of columns returned in the result set. An example follows: // Execute the query $query = “SELECT sku, name FROM product ORDER BY name”; $result = $dbh->query($query); // Report how many columns were returned echo “There were “.$result->columnCount().” product fields returned.”; Sample output follows: There were 2 product fields returned. fetch() mixed PDOStatement::fetch ([int fetch_style [, int cursor_orientation [, int cursor_offset]]]) The fetch() method returns the next row from the result set, or FALSE if the end of the result set has been reached. The way in which each column in the row is referenced depends upon how the fetch_style parameter is set. Six settings are available, including: PDO_FETCH_ASSOC: Causes fetch() to retrieve an array of values indexed by the column name. PDO_FETCH_BOTH: Causes fetch() to retrieve an array of values indexed by both the column name and the numerical offset of the column in the row (beginning with 0). This is the default. PDO_FETCH_BOUND: Causes fetch() to return TRUE and instead assign the retrieved column values to the corresponding variables as specified in the bindParam() method. See the later section Setting Bound Columns for more information about bound columns.
If you are in need for chaep and reliable webhost to host your website, our recommendation is http web server services.

Leave a Reply