tags:

views:

188

answers:

1

I am learning how to use prepared statements with php 5 mysqli objects and I am having trouble getting the basic result binding to work. I am following the example code from php.net but something isn't working, the bound results are always NULL. Here is what I have

/* prepare statement */

if ($stmt = $DB->mysqli->prepare("SELECT `alias`,`nameFirst`,`nameLast`,`email`,`access_level` FROM `users` WHERE `alias` LIKE CONCAT('%',?,'%') LIMIT 20;")) {

                   $stmt->bind_param('s',$alias);

                    $stmt->execute();

                    /* bind variables to prepared statement */
                    $stmt->bind_result($col1, $col2);

                    /* fetch values */
                    while ($stmt->fetch()) {
                    echo "COL 1=".$col1." | COL2=".$col2."<br />";
                    }

                    /* close statement */
                    $stmt->close();
                } else echo "NO DICE";
A: 

Ooops, I missed the note right on the php docs:

Note that all columns must be bound after mysqli_stmt_execute() 
and prior to calling mysqli_stmt_fetch().

Found the answer here:

http://stackoverflow.com/questions/1019959/prepared-statement-not-returning-anything

Corbin Tarrant