Prepared Statement not working (mysql 5)
| From: | Marco Bascietto | Date: | Thu, 14 Jul 2005 11:15:07 +0000 |
| Subject: | Prepared Statement not working (mysql 5) | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-39947@lists.php.net to get a copy of this message | ||
Hello list,
The following example script uses prepared statements to bind input and
output parameters It works flowlessy using php 5 & mysqli on a client
machine and MySQL 5.0.7 beta on the server (192.168.0.2):
1: <?php
2: $m = new mysqli('192.168.0.2', 'xxx', 'xxx');
3: $m->select_db('xxx');
4:
5: $sql = "SELECT des FROM comune WHERE descrizione LIKE ?";
6: $param='tre%';
7:
8: $stmt = $m->stmt_init();
9:
10: if ($stmt->prepare($sql)) {
11:
12: $stmt->bind_param('s', $param);
13: $stmt->execute();
14: $stmt->bind_result($col1);
15:
16: echo "<p>";
17: while ($stmt->fetch()) {
18: echo "$col1<br/>";
19: }
20: echo "</p>";
21:
22: $stmt->close();
23: }
24:
25: $m->close();
26:
27: ?>
Now, upon moving the script on to the server and replacing line 2 with
2: $m = new mysqli('localhost', 'xxx', 'xxx');
it stops working (ie no output at all on screen).
Removing the bound output parameter (line 14) results in a mock "too
many parameters to bind_param" error on line 12.
Replacing the PS with a simple query makes the script work again.
The PS at the mysql command interface level is working as expected.
It looks like there is a problem with mysqli PS when the client and the
server share the same machine.
Does anyone have a clue on what is going on or point me to some tests I
can do?
Thank you all,
marco