Re: Re: Variable number of parameters
| From: | Shawn McKenzie | Date: | Thu, 07 Aug 2008 17:37:08 +0000 |
| Subject: | Re: Re: Variable number of parameters | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-277832@lists.php.net to get a copy of this message | ||
Philip Thompson wrote:
Oops! Meant to send this to the list.... On Aug 7, 2008, at 9:31 AM, Philip Thompson wrote:$args = func_get_args(); call_user_func_array(array(&$this->statement, 'bind_param'), $args); } Maybe? -ShawnOn Aug 6, 2008, at 4:25 PM, Shawn McKenzie wrote:"innerHTML is a string. The DOM is not a string, it's a hierarchal object structure. Shoving a string into an object is impure and similar to wrapping a spaghetti noodle around an orange and calling it lunch." function bind () {Philip Thompson wrote:The bind_param() function is a built-in PHP MySQLi function (http://php.net/mysqli_bind_param). I can't change how this accepts args (of course). Thanks for your thoughts anyway. =D ~PhilipIs it possible to grab a variable number of parameters and send the appropriate amount to another function? <?php // Some class $this->db->prepare("SELECT * FROMI'm confused as your code looks like it's already doing what you're asking. It's hard to tell without seeing what bind_param() looks like. But just a thought to use arrays in one of two ways: // 1. $this->db->bind('ii', $id1, $id2); function bind () {tableWHERE (id=?)"); $this->db->bind('ii', $id1); $this->db->prepare("SELECT * FROMtableWHERE (id=? ANDother_id=?)"); $this->db->bind('ii', $id1, $id2); // DB class function bind () { $args = func_get_args(); $this->statement->bind_param($args[0], $args[1], ...); } ?> Ok, is it possible to send any number of variables to db->bind() in order to send those to statement->bind_param()? Or, if someone else has a better db abstraction method, feel free to educate... Thanks, ~Phil$args = func_get_args(); $this->statement->bind_param($args); // then bind_param() can count the number of args and use them} //2. $this->db->bind('ii', array($id1, $id2)); function bind ($var, $ids) {// pass thru to bind_param() $this->statement->bind_param($var, $ids); // then bind_param() can use the $ids array // or count the ids and send individual args to bind_param()} As I said, it's kind of hard to tell without knowing exactly what you want to achieve. One of the more elegant ways that I have seen is to pass required args and then an array of args that the receiving function can use, like: $this->db->bind('ii', array('someoption'=>$id1, 'feature'=>$id2, 'action'=>'doit')); Need more info on the desired outcome. -Shawn