php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #62598 Mistake in user comment
Submitted: 2012-07-18 12:23 UTC Modified: 2012-07-19 00:59 UTC
From: the dot music dot of dot the dot ainur at gmail dot com Assigned: aharvey (profile)
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS: N/A
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: the dot music dot of dot the dot ainur at gmail dot com
New email:
PHP Version: OS:

 

 [2012-07-18 12:23 UTC] the dot music dot of dot the dot ainur at gmail dot com
Description:
------------
On this documument page : http://php.net/manual/fr/mysqli-stmt.bind-param.php
Last user comment (nick9v at hotmail dot com 30-Jun-2012 10:12) is very useful but contains a little mistake.

The function 
public function add( $type, $value ){
        $this->values[] = $value;
        $this->types .= $type;
    }

Should be 
public function add( $type, &$value ){
        $this->values[] = $value;
        $this->types .= $type;
    }

Otherwise, this : 
call_user_func_array( array($stm, 'bind_param'), $bindParam->get());

Will return this :
Warning: Parameter 2 to mysqli_stmt::bind_param() expected to be a reference, value given



Test script:
---------------
// class BindParam copied from user comment

$bindParam = new BindParam();
$qArray = array();
$column1NewValue = $_POST['column1'];
$column2NewValue = $_POST['column1'];

$qArray[] = 'Column1 = ?';
$bindParam->add('i', $column1NewValue );
$qArray[] = 'Column2 = ?';
$bindParam->add('s', $column2NewValue );

$query = 'UPDATE myTable SET ';
$query.= implode(' , ', $qArray);
$query.= ' WHERE PKeyID= ?';
$bindParam->add('i', $lineToUpdate);

$stmt = $mysqli->prepare($query);

call_user_func_array(array($stmt, 'bind_param'), $bindParam->get());

$stmt->execute();
$stmt->close();

Expected result:
----------------
Row in database properly updated.

Actual result:
--------------
( ! ) Warning: Parameter 2 to mysqli_stmt::bind_param() expected to be a reference, value given in c:\path\myfile.php on line 157
Call Stack
#	Time	Memory	Function	Location
1	0.0010	297832	{main}( )	..\myfile.php:0
2	0.0059	322952	call_user_func_array ( )	..\myfile.php:157

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-07-18 19:26 UTC] mail+php at requinix dot net
Feel free to post your own comment correcting the mistake :)
 [2012-07-18 21:34 UTC] the dot music dot of dot the dot ainur at gmail dot com
I reported a bug because, when adding a comment, I get a page whi says this : 
[...]
What not to enter
[...]
- References to other notes or authors. This is not a forum, so we neither encourage nor permit discussions here. Further, if a note is referenced directly, and that note is later removed or modified, it can cause confusion.
- Code collaboration or improvements. This is not to suggest that your code modification is not good, perhaps even great, but this just isn't the place to show it off. We don't even accept all original code submissions. Your best bet is to publish it on your blog or via another medium. 
[...]
 [2012-07-19 00:59 UTC] aharvey@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: aharvey
 [2012-07-19 00:59 UTC] aharvey@php.net
Yep, posting a bug was definitely the right way to go here.

Fixed; thanks!
 [2012-07-24 02:49 UTC] nick9v at hotmail dot com
To fix the problem you need to change:

call_user_func_array( array($stm, 'bind_param'), $bindParam->get());

To:

$bp = $bindParam->get();
call_user_func_array( array($stm, 'bind_param'), $bp);

That's it!
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 23:00:01 2026 UTC