php.net |  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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
48 + 39 = ?
Subscribe to this entry?

 
 [2006-10-23 13:05 UTC] mark dot 2391 at blueyonder dot co dot uk
Description:
------------
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,
Mark


Reproduce code:
---------------
<?php
// 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);
$myDasStmt->execute($mysqlParams);

class MyDasStmt
{
    protected $mysqlParamsStringTypes;
    protected $stmt;

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

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


Expected result:
----------------
N/A

Actual result:
--------------
N/A

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-01-01 23:40 UTC] jani@php.net
-Package: Feature/Change Request +Package: MySQLi related
 [2011-01-06 15:00 UTC] uw@php.net
-Assigned To: +Assigned To: mysql
 [2011-01-06 15:00 UTC] uw@php.net
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?

Or:

  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?

Or:

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

Ulf
 [2011-02-09 15:49 UTC] andrey@php.net
-Status: Assigned +Status: Feedback
 [2011-11-04 10:06 UTC] uw@php.net
-Status: Feedback +Status: No Feedback
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Fri Oct 07 09:05:52 2022 UTC