PHP Prepared Statements - with An Undefined Number of Variables Passed to bind_result()

/ Published in: PHP
Save to your folder(s)

When retrieving table rows with PHP and prepared statements, you must use a method called bind_result() and pass in a variable name for each column that is being returned from the database. For example, if you are selecting three columns (say, id, title, body), bind_result must be passed three variables names: bind_result($id, $title, $body). This becomes a pain in the butt when, for example, if it is within a class file, where you will not always know how many columns are being selected from the table. This code gets around that.

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.