ID: 31037 Comment by: putu dot dondo at gmail dot com 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:
i get this error too! i use WAMP5 on windowsXP Previous Comments: ------------------------------------------------------------------------ [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. ------------------------------------------------------------------------ [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) ------------------------------------------------------------------------ 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
