用什么替换MySQLi的mysql_result [英] What to replace mysql_result with for MySQLi

查看:61
本文介绍了用什么替换MySQLi的mysql_result的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

mysql_result替换什么?

我现在正在观看教程,但该教程是在2011年制作的,因此现在无法正常使用. 在这种情况下,如果您告诉我在此处替换mysql_result的内容以及放在括号中的内容,我将不胜感激

function update_count() {
    global $link;
    $query  = "SELECT `count`, FROM `hits_count`";
    if($query_run = mysqli_query($link, $query)) {
        $count = mysql_result($query_run, 0, 'count');
        $count_inc = $count + 1;
        echo $count;
    } 
}
update_count();

解决方案

mysqli_query 返回 mysqli_result对象.从那里,您可以获取想要的价值.

if($query_run = mysqli_query($link, $query)) {
    // This gets you one row at a time, use a while if there are multiple rows
    // while($row = mysqli_fetch_assoc($query_run)){}
    $row = mysqli_fetch_assoc($query_run);
    $count = $row['count'];
    // Do whatever with $count
}

what to replace mysql_result with?

im watching a tutorial now but it was made in 2011 so it is not working now. Here is the situation, I will be very grateful if you tell me what to replace mysql_result with here, and what to put in the parenthesis

function update_count() {
    global $link;
    $query  = "SELECT `count`, FROM `hits_count`";
    if($query_run = mysqli_query($link, $query)) {
        $count = mysql_result($query_run, 0, 'count');
        $count_inc = $count + 1;
        echo $count;
    } 
}
update_count();

解决方案

mysqli_query returns you a mysqli_result object. From there, you can get the value you want.

if($query_run = mysqli_query($link, $query)) {
    // This gets you one row at a time, use a while if there are multiple rows
    // while($row = mysqli_fetch_assoc($query_run)){}
    $row = mysqli_fetch_assoc($query_run);
    $count = $row['count'];
    // Do whatever with $count
}

这篇关于用什么替换MySQLi的mysql_result的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆