Hans Lellelid wrote:


I'm writing a db abstraction layer driver for MySQLi. I'm glad to finally get a chance to play around with these new functions, but am completely stumped by this question:

Is there no way to get back a standard resultset when using prepared statement queries?

I can't believe this would be the case, but it seems that the only option when using prepared statements is to call myslqi_stmt_bind_result(), binding results to php variables and then call mysqli_stmt_fetch($stmt) until it returns null. i.e.

    $sql = "SELECT name, age FROM friends WHERE country = ?";
    $stmt = mysqli_prepare($link, $sql);

    $country = "Haiti";
    mysqli_bind_param($stmt, "s", $country);


       /* bind result variables */
       mysqli_stmt_bind_result($stmt, $name, $age);

    /* fetch values */
    while (mysqli_stmt_fetch($stmt)) {
        printf ("%s (%s)\n", $name, $code);

What I want to be able to do is use things like mysqli_fetch_assoc() instead of this weird, side-effect-prone mysqli_stmt_fetch() to retrieve the results.

I don't see the solution, but I hope I'm just missing something because I've been staring at it too long.

No you're not missing anything...
I ran into the same thing...
So I ended up simulating "prepared" statements via php itself.
The way the mysqli extension is currently setup, is that you can either
use the normal functions by themselves, or you use the statement functions
by themselves.  They cannot be used together, which I think....
Never mind, I'll keep my thoughts to myself...

PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to