ID:               31037
 Comment by:       joey at alegria dot co dot jp
 Reported By:      php at trafex dot nl
 Status:           No Feedback
 Bug Type:         MySQLi related
 Operating System: Fedora core 1
 PHP Version:      5CVS-2005-04-26
 Assigned To:      georg
 New Comment:

Upgraded PHP to 5.0.4-10.5 and that got the mysqli_stmt_bind_param()
function working again with my scripts that only had INSERT SQL queries
in them.

The error still persisted when binding input parameters on SELECT
queries, however this can be fixed by paying close attention to syntax.
DO NOT use the same syntax you would for a normal query. When sending a
prepared statement it is important to omit quotation marks ('?') around
the placeholders. Prepared statement don't require them for strings.

EXAMPLE:

$username='foo';
$id=1;
$prepare="SELECT * FROM test WHERE user='?' and id=?";
$sql->stmt=mysqli_stmt_init($sql->db);
mysqli_stmt_prepare($sql->stmt,$prepare);
echo mysqli_stmt_param_count($sql->stmt); // returns 0
mysqli_stmt_bind_param($sql->stmt,'si',$username,$id); // throws an
error

That throws an error however...

$username='foo';
$id=1;
$prepare='SELECT * FROM test WHERE user=? and id=?';
$sql->stmt=mysqli_stmt_init($sql->db);
mysqli_stmt_prepare($sql->stmt,$prepare);
echo mysqli_stmt_param_count($sql->stmt); // returns 2
mysqli_stmt_bind_param($sql->stmt,'si',$username,$id); // works OK

The PHP documentation is not mistaken in the examples it gives for
prepared statements but perhaps it could be a little more explicit in
pointing out this easy-to-make syntax error.


Previous Comments:
------------------------------------------------------------------------

[2006-02-07 11:31:56] joey at alegria dot co dot jp

Very bizzar (and frustrating). But I am 100% sure on this. I had no
errors from using mysqli_bind_param(); accross a number of scripts that
input data to MySQL. However, As soon as I made a script that requested
data from the database that also used mysqli_bind_result(), everything
that had mysqli_bind_param() started throwing up 

"Warning: mysqli_stmt::bind_param() [function.bind-param]: Number of
variables doesn't match number of parameters in prepared statement
in..."

even on scripts that worked fine before! Because I can find no way to
revert it to the working state, I also can't supply a sample script. Is
it possible the fist use of mysqli_bind_result() corrupts part of PHP?

I used PHP5.0.3 with MySQL 4.1.19 on Fedora Core 4 (x86)

------------------------------------------------------------------------

[2005-10-06 19:09:23] pavel dot stratil-jun at fenix dot cz

I get this error with PHP 5.0.4 on Sun Solaris 9 with Mysql 5.07beta.
Can you look into this again please?

------------------------------------------------------------------------

[2005-05-04 01:00:04] php-bugs at lists dot php dot net

No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".

------------------------------------------------------------------------

[2005-04-26 15:11:32] [EMAIL PROTECTED]

Cannot reproduce with different combinations of client and server API
as well as PHP versions

[EMAIL PROTECTED]:~/test> php 31037.php
Client version: 50004
Server version: 40112
Name: foo
[EMAIL PROTECTED]:~/test> php 31037.php
Client version: 50004
Server version: 40110
Name: foo
[EMAIL PROTECTED]:~/test> php 31037.php
Client version: 40110
Server version: 40110
Name: foo


Did you recompile PHP with 4.1.10 library or it is still using 4.1.7?

------------------------------------------------------------------------

[2005-03-06 18:26:47] [EMAIL PROTECTED]

Assigning to the maintainer..


------------------------------------------------------------------------

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/31037

-- 
Edit this bug report at http://bugs.php.net/?id=31037&edit=1

Reply via email to