Req #39235 [Fbk->NoF]: Permit parameters in execute()
| From: | uw@php.net | Date: | Fri, 04 Nov 2011 10:06:35 +0000 |
| Subject: | Req #39235 [Fbk->NoF]: Permit parameters in execute() | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-164871@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=39235&edit=1
ID: 39235
Updated by: uw@php.net
Reported by: mark dot 2391 at blueyonder dot co dot uk
Summary: Permit parameters in execute()
-Status: Feedback
+Status: No Feedback
Type: Feature/Change Request
Package: MySQLi related
Operating System: Debian GNU/Linux
PHP Version: 5.1.6
Assigned To: mysql
Block user comment: N
Private report: N
Previous Comments:
------------------------------------------------------------------------
[2011-01-06 15:00:04] 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
------------------------------------------------------------------------
[2006-10-23 13:05:14] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=39235&edit=1