Web server setup - 570 CHAPTER 23 INTRODUCING PDO The resulting
570 CHAPTER 23 INTRODUCING PDO The resulting output follows. Note that the product name and SKU don t correspond to the correct values as provided in the sample data table. Product: AquaSmooth Toothpaste (PO988932) setFetchMode() boolean PDOStatement::setFetchMode (int mode) If your script requires that fetch() or fetchAll() be used several times, and you plan on using a fetching setting other than the default PDO_FETCH_BOTH, you can save some typing by declaring a new default setting at the top of the script using setFetchMode(). Just set the mode parameter to the appropriate setting (see the previous introduction to fetch() for a list of available settings), and all subsequent calls to fetch() or fetchAll() will produce result sets capable of being referenced accordingly. Setting Bound Columns In the previous section you learned how to set the fetch_style parameter in the fetch() and fetchAll()methods to control how the resultset columns will be made available to your script. You were probably intrigued by the PDO_FETCH_BOUND setting, because it seems to enable you to avoid an additional step altogether when retrieving column values, and instead just assign them automatically to predefined variables. Indeed this is the case, and it s accomplished using the bindColumn() method, introduced next. bindColumn() boolean PDOStatement::bindColumn (mixed column, mixed ¶m [, int type [, int maxlen [, mixed driver_options]]]) The bindColumn() method is used to match a column name to a desired variable name, which, upon each row retrieval, will result in the corresponding column value being automatically assigned to the variable. The column parameter specifies the column offset in the row, whereas the ¶m parameter defines the name of the corresponding variable. You can set constraints on the variable value by defining its type using the type parameter, and limiting its length using the maxlen parameter. Six type parameter values are supported. See the earlier introduction to bindParam() for a complete listing. The following example selects the sku and name columns from the product table where rowIDequals 1, and binds the results according to a numerical offset and associative mapping, respectively: // Connect to the database server $dbh = new PDO(”pgsql:host=localhost;dbname=corporate”, “websiteuser”, “secret”);
Searching for affordable and proven webhost to host and run your servlet applications? Go to Linux Web Hosting services and you will find it.