|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #39235 Permit parameters in execute()
Submitted: 2006-10-23 13:05 UTC Modified: 2011-11-04 10:06 UTC
From: mark dot 2391 at blueyonder dot co dot uk Assigned: mysql (profile)
Status: No Feedback Package: MySQLi related
PHP Version: 5.1.6 OS: Debian GNU/Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: mark dot 2391 at blueyonder dot co dot uk
New email:
PHP Version: OS:


 [2006-10-23 13:05 UTC] mark dot 2391 at blueyonder dot co dot uk
I want to convert to MySqli from PDO's MySql driver as I'm hitting a known bug in PDO that isn't getting fixed and I figure MySqli would be faster anyway.

However, MySqli appears to be restrictive when compared to PDO in its insistence that I use bind_params(). PDO allows the alternative to pass Mysql parameters as an array to its execute() method.

My Mysql parameters are passed to me as an array in my code.
I do not know a way in PHP of passing an array of these parameters to MySQLi while it insists on using bind_params which in turn insists on a fixed list of named variables.

As I say, PDO copes with this as it's execute() method offers the alternative choice while params to MySqli's execute() are marked as void, and so it seems to me impossible to implement my Data Access Service layer (which manages DB access on similar lines to the PHP SDO extension) with Mysqli at the moment unless I completely lose the advantage of prepared statements.

The code below hopefully illustrates the kind of usage I need (and as I say, PDO allows). Perhaps there is a workaround I have not thought of.

Thanks in advance for any comments/tips,

Reproduce code:
// I propose this change to the mysqli_stmt_execute() syntax allowing me to do something like the following:
// bool mysqli_stmt_execute ( mysqli_stmt stmt [string types, array input_parameters] )

$dbh = new mysqli("localhost", "my_user", "my_password", "world");
$sql = 'INSERT INTO TableA VALUES (?, ?)';
$mysqlParamsStringTypes = 'is';
$mysqlParams = array('1', 'a');

$myDasStmt = new MyDasStmt($dbh, $sql, $mysqlParamsStringTypes);

class MyDasStmt
    protected $mysqlParamsStringTypes;
    protected $stmt;

    public function __construct($dbh, $sql, $mysqlParamsStringTypes)
        $this->stmt = $dbh->stmt_init();

    public function execute(array $mysqlParams)
        $this->stmt->execute($this->mysqlParamsStringTypes, $mysqlParams);
        // ...

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-01-01 23:40 UTC]
-Package: Feature/Change Request +Package: MySQLi related
 [2011-01-06 15:00 UTC]
-Assigned To: +Assigned To: mysql
 [2011-01-06 15:00 UTC]
What shall happen to bound parameters after the first execution (error or not) of the statement? Shall mysqli try to use the same parameters for a new call to execute even if no values are passed to the execute method?

  stmt->execute(bound_values) -> OK
  stmt->execute()             -> reuse bound_values?

  stmt->execute(bound_values) -> error
  stmt->execute()             -> reuse bound_values?


  stmt->execute(bound_values) -> OK
  stmt->execute()             -> error: no values given

What shall happen if parameters have been bound but execute gets called with new parameters:

  stmt->bind(value)             -> use value
  stmt->execute(another_value)  -> use another_value?


  stmt->bind(value)             -> use value
  stmt->execute(another_value)  -> error: must not mix syntax

 [2011-02-09 15:49 UTC]
-Status: Assigned +Status: Feedback
 [2011-11-04 10:06 UTC]
-Status: Feedback +Status: No Feedback
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 12 13:01:33 2024 UTC