I'd really like to mirror PDO here, and with `bind_param` supporting an 
unlimited number of arguments, it makes that third positional argument clunky. 
I still say a separate function to bind a sole value would be enough and avoids 
any confusion with the existing method.

Joel Hutchinson


-----Original Message-----
From: Bruce Weirdan <weir...@gmail.com> 
Sent: Monday, November 25, 2019 5:41 PM
To: Joel Hutchinson <joel.hutchin...@onlinecommercegroup.com>
Cc: internals@lists.php.net
Subject: Re: [PHP-DEV] mysqli needs a method to bind a single parameter

On Mon, Nov 25, 2019 at 8:06 PM Joel Hutchinson 
<joel.hutchin...@onlinecommercegroup.com> wrote:

> This proposal would leave the previous mysqli_stmt_bind_param mostly 
> untouched. Instead, the two could be used in tandem $sql = 'SELECT 
> name FROM db.customer WHERE record_id = ? AND shipping_zip = ?';
> if(isset($_GET['zip'])) $sql .= ' AND billing_zip = ?';
>
> $stmt = $db->prepare($sql);
> $stmt->bind_param('is', $_GET['record_id'], $_GET['shipping_zip']);
> if(isset($_GET['zip'])) $stmt->bind_single('s', $_GET['billing_zip'], 
> 3); $stmt->execute(); This necessitates a small change to 
> mysqli_stmt_bind_param, in that the current function has a parameter check to 
> ensure that the number of binds matches the number of parameters in the query 
> (or else it emits an E_WARNING). That check would have to move to 
> mysqli_stmt_execute, if it is still to be performed.

If `bind_param` is allowed to do incomplete bind (as in your example where you 
supply 2 out of 3 required bound parameters) t hen there's no need for 
additional method, as you could simply do:

  if (isset($_GET['zip'])) $stmt->bind_param('s', $_GET['zip']);


--
  Best regards,
      Bruce Weirdan                                     mailto:weir...@gmail.com

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to