开发者

mysqli bind_result/fetch problem

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`,`nameFi开发者_如何学Crst`,`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";


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:

Prepared Statement not returning anything


Or, you can all fields in an array like $cols[]. While printing you can use echo $cols[0].$cols[1] and so on.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜