ID:               31037
 Comment by:       droppse at wjh dot harvard dot edu
 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:

Updating the mysql client lib's resolved this problem on XP Pro, WAMP.


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

[2006-03-28 13:05:55] putu dot dondo at gmail dot com

i get this error too!
i use WAMP5 on windowsXP

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

[2006-02-14 01:28:07] skotch at online dot stack dot net

After a couple of nights I've found the solution. Upgrading to newest
versions of PHP and MySQL don't solve the problem.Both PHP and MySQL
have a lib named libmysql but those libs are not the same. Make PHP to
use php/libmysql and everythig will be OK. For ensure the result just
rename the libmysql library from MySQL install and execute your php
script correct!

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

[2006-02-13 07:09:06] [EMAIL PROTECTED]

> Client version: 40107 Server version: 50018

Why don't upgrade your client version?
Recompile your PHP extensions or download an actual version from
http://dev.mysql.com/downloads/connector/php/

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

[2006-02-13 01:03:14] mczub at newcomo dot pl

This script (with 1 variable):
------------------------------
<?php
$mysql = new mysqli("localhost", "***", "***", "test");
printf("Client version: %s\n", $mysql->client_version); 
printf("Server version: %s\n", $mysql->server_version); 
$mysql->query("DROP TABLE IF EXISTS temp_table"); 
$mysql->query("CREATE TABLE temp_table(username varchar(20), user_id
int)"); 
$mysql->query("INSERT INTO temp_table VALUES ('foo', 1)"); 
if ($stmt = $mysql->prepare("SELECT username FROM temp_table WHERE
user_id = ?")) 
{ 
    $stmt->bind_param('i', $user_id);
    $user_id = 1;
    $stmt->execute(); 
    $stmt->bind_result($name); 
    $stmt->fetch(); 
    printf("Name: %s\n", $name); 
    $stmt->close(); 
} 
$mysql->close(); 
?>

Output:
-------
Client version: 40107 Server version: 50018 Name:


This script (with 2 variables):
------------------------------
<?php
$mysql = new mysqli("localhost", "***", "***", "test");
printf("Client version: %s\n", $mysql->client_version); 
printf("Server version: %s\n", $mysql->server_version); 
$mysql->query("DROP TABLE IF EXISTS temp_table"); 
$mysql->query("CREATE TABLE temp_table(username varchar(20), user_id
int, user_id2 int)"); 
$mysql->query("INSERT INTO temp_table VALUES ('foo', 1, 2)"); 
if ($stmt = $mysql->prepare("SELECT username FROM temp_table WHERE
user_id = ? AND user_id2 = ?")) 
{ 
    $stmt->bind_param('ii', $user_id, $user_id2);
    $user_id = 1;
    $user_id2 = 2; 
    $stmt->execute(); 
    $stmt->bind_result($name); 
    $stmt->fetch(); 
    printf("Name: %s\n", $name); 
    $stmt->close(); 
} 
$mysql->close(); 
?>

Output:
-------
Client version: 40107 Server version: 50018
Warning: mysqli_stmt::bind_param() [function.bind-param]: Number of
variables doesn't match number of parameters in prepared statement in
C:\wamp\www\learn\mysql.php on line 12
Name:


It's weird...

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

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

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.

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

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