问题描述
我正在为这个警告而苦苦挣扎
I am struggling with this warning
我在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
返回带有索引键和关联键的数组,使用更多的内存并使foreach
或list
语句以意外的方式运行.
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,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!