11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

www.it-ebooks.infoCHAPTER 30 • USING <strong>PHP</strong> WITH MYSQL?>// Cycle through the results and output the datawhile($stmt->fetch())printf("%s, %s, %s ", $sku, $name, $price);// Recuperate the statement resources$stmt->close();// Close the connection$mysqli->close();Executing Listing 30-2 produces output similar to the following:A0022JKL, pants, $18.99, Pair of blue jeansB0007MCQ, shoes, $43.99, black dress shoesZ4421UIM, baseball cap, $12.99, College football baseball capRetrieving Rows from Prepared StatementsThe fetch() method retrieves each row from the prepared statement result and assigns the fields to thebound results. Its prototype follows:class mysqli {boolean fetch()}See Listing 30-2 for an example of fetch() in action.Using Other Prepared Statement MethodsSeveral other methods are useful for working with prepared statements; they are summarized in Table30-1. Refer to their namesakes earlier in this chapter for an explanation of behavior and parameters.Table 30-1. Other Useful Prepared Statement MethodsMethodaffected_rows()free()DescriptionReturns the number of rows affected by the last statement specified by thestmt object. Note this is only relevant to insertion, modification, and deletionqueries.Recuperates memory consumed by the statement specified by the stmtobject.604

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!