I can't get prepared statements to work in PHP 5.12 using their example script and the 'world' database. I've tried using prepared statements directly from the mysql client, and it works fine. Other functions from ext/mysqli work fine as well. But when I run the following code, I only get "Amersfoort is in district "
<?php $mysqli = new mysqli("localhost", "my_user", "my_password", "world"); if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit();
}
$city = "Amersfoort";
$stmt = $mysqli->stmt_init(); if ($stmt->prepare("SELECT District FROM City WHERE Name=?")) { $stmt->bind_param("s", $city); $stmt->execute(); $stmt->bind_result($district); $stmt->fetch(); printf("%s is in district %s\n", $city, $district); $stmt->close();
> I can't get prepared statements to work in PHP 5.12 using their example > script and the 'world' database. I've tried using prepared statements > directly from the mysql client, and it works fine. Other functions > from ext/mysqli work fine as well. But when I run the following code, > I only get "Amersfoort is in district "
> $stmt = $mysqli->stmt_init(); > if ($stmt->prepare("SELECT District FROM City WHERE Name=?")) { > $stmt->bind_param("s", $city); > $stmt->execute(); > $stmt->bind_result($district); > $stmt->fetch(); > printf("%s is in district %s\n", $city, $district); > $stmt->close(); > } > $mysqli->close(); > ?>
The value is some string, Maastricht maybe? var_dump is showing NULL, and $mysqli->error is empty as well. It's nothing to do with the database, I had the same problems on my own code. I just set up an exact duplicate of the PHP example code to confirm that is is a problem. If it's relevant, I'm running PHP 5.12 and MySQL 5.0.18 on Windows. All other mysqli functions are working fine. Thanks for any suggestions!
John Jawed wrote: > Could you paste the code as you have it? Including where you bind it.
> On 2/11/06, mike...@gmail.com <mike...@gmail.com> wrote:
> > My mistake, there is an error, but only after bind_result is called: > > "Using unsupported buffer type: 254 (parameter: 1)"
The code was actually in my first post, but I've got it figured out anyway.
I installed the client library from MySQL and it fixed the problem. So much for PHP's big noise about keeping mysqli up to date with MySQL! Strangely enough, phpinfo() claimed my client library version was 5.0.18 beforehand, but the new version seems to have fixed some problem.
So next time somebody running Windows shows up here with a problem, send them to http://dev.mysql.com/downloads/connector/php/ first to make sure they have the latest client library.
> John Jawed wrote: > > Could you paste the code as you have it? Including where you bind it.
> > On 2/11/06, mike...@gmail.com <mike...@gmail.com> wrote:
> > > My mistake, there is an error, but only after bind_result is called: > > > "Using unsupported buffer type: 254 (parameter: 1)"
> The code was actually in my first post, but I've got it figured out > anyway.
> I installed the client library from MySQL and it fixed the problem. So > much for PHP's big noise about keeping mysqli up to date with MySQL! > Strangely enough, phpinfo() claimed my client library version was > 5.0.18 beforehand, but the new version seems to have fixed some > problem.
> So next time somebody running Windows shows up here with a problem, > send them to http://dev.mysql.com/downloads/connector/php/ first to > make sure they have the latest client library.
> Good information, will have to keep that in mind. What OS are you using by > the way?
> On 2/13/06, mike...@gmail.com <mike...@gmail.com> wrote:
> > John Jawed wrote: > > > Could you paste the code as you have it? Including where you bind it.
> > > On 2/11/06, mike...@gmail.com <mike...@gmail.com > wrote:
> > > > My mistake, there is an error, but only after bind_result is called: > > > > "Using unsupported buffer type: 254 (parameter: 1)"
> > The code was actually in my first post, but I've got it figured out > > anyway.
> > I installed the client library from MySQL and it fixed the problem. So > > much for PHP's big noise about keeping mysqli up to date with MySQL! > > Strangely enough, phpinfo() claimed my client library version was > > 5.0.18 beforehand, but the new version seems to have fixed some > > problem.
> > So next time somebody running Windows shows up here with a problem, > > send them to http://dev.mysql.com/downloads/connector/php/ first to > > make sure they have the latest client library.