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 MYSQLEverything found in this example should be quite straightforward, except perhaps the query itself.Notice that question marks are being used as placeholders for the data, namely the user’s ID and theURLs. The bind_param() method is called next, binding the variables $userid and $url to the fieldplaceholders represented by question marks, in the same order in which they’re presented in themethod. This query is prepared and sent to the server, at which point each row of data is readied andsent to the server for processing using the execute() method. Finally, once all of the statements havebeen processed, the close() method is called, which recuperates the resources.■ Tip If the process in which the array of form values are being passed into the script isn’t apparent, see Chapter13 for an explanation.Binding VariablesAfter a query has been prepared and executed, you can bind variables to the retrieved fields by using thebind_result() method. Its prototype follows:class mysqli_stmt {boolean bind_result(mixed &var1 [, mixed &varN])}For instance, suppose you want to return a list of the first 30 products found in the products table.The code found in Listing 30-2 binds the variables $sku, $name, and $price to the fields retrieved in thequery statement.Listing 30-2. Binding Results with the mysqli Extension

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

Saved successfully!

Ooh no, something went wrong!