mysqli_query()期望参数1为mysqli, [英] mysqli_query() expects parameter 1 to be mysqli,

查看:201
本文介绍了mysqli_query()期望参数1为mysqli,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为这个警告而苦苦挣扎

I am struggling with this warning

mysqli_query()期望参数1为mysqli,给出字符串

mysqli_query() expects parameter 1 to be mysqli, string given

我在phpmyadmin的SQL部分使用了查询,它可以工作,但是mysqli_query返回此错误.我与数据库的连接已连接,否则编译器将如何通过"if"条件传递给mysqli_query.我不明白.请帮忙.

I have used the query in SQL section in phpmyadmin, it works but mysqli_query is returning this error. my connection to the database is connected or else how the compiler would even pass through "if" conditions to mysqli_query. I do not understand. please help.

以下是我的代码

include("../class/config.php");


if($_REQUEST["subuser"]){

@extract($_REQUEST);

$dbobject = new dbconnection();

$con = $dbobject->getconnection();


    if($con)
    { 



        $dbresult = $dbobject->selectdatabase();
        if($dbresult)
        {
                   $sql = "select * from admin where username='".$username."' 
                           and pswd = '".$pswd."'";

                  $record = mysqli_query($sql,$con);

                while ($row = mysql_fetch_array($record ))
                {
                   echo $row['aid'];
                }
        }
        else
        {
              echo mysqli_error();  
        }
    }
    else
    {
        echo mysqli_error();    
    }   
}

推荐答案

使用该功能时,连接/链接优先.

The connection/link goes first when using that function.

$record = mysqli_query($con,$sql);

您将遇到的下一个问题是mysql_fetch_array是使用错误的函数.您应该使用mysqli_fetch_array.

The next issue that you'll run into is that mysql_fetch_array is the wrong function to use. You should use mysqli_fetch_array.

通常,最好使用mysqli_fetch_row获取索引数组,或者使用mysqli_fetch_assoc获取关联数组. mysqli_fetch_array返回带有索引键和关联键的数组,使用更多的内存并使foreachlist语句以意外的方式运行.

It's also (generally) better to use mysqli_fetch_row to get an indexed array, or mysqli_fetch_assoc to get an associative array. mysqli_fetch_array returns an array with both indexed and associative keys, using more memory and making foreach or list statements behave in an unexpected manner.

这篇关于mysqli_query()期望参数1为mysqli,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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