php 警告:mysql_fetch_array() 期望参数 1 是资源,给定的对象

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4635007/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 13:46:48  来源:igfitidea点击:

warning:mysql_fetch_array() expects parameter 1 to be resource, object given

phpmysqliprepared-statement

提问by Sam Gabriel

I am getting the above warning when I try to run this code:

当我尝试运行此代码时收到上述警告:

$mysqli=new mysqli("localhost", "***", "***","***") or die(mysql_error());


              function checklogin($username, $password){
                global $mysqli;


                $result = $mysqli->prepare("SELECT * FROM users WHERE username = ?");
                $result->bind_param("s", $username);
                $result->execute();

            if($result != false){

                $dbArray=mysql_fetch_array($result);

回答by Chandu

You are mixing mysql and mysqli calls in your code. Use mysqli_fetch_arrayinstead of mysql_fetch_array.

您在代码中混合了 mysql 和 mysqli 调用。使用mysqli_fetch_array代替mysql_fetch_array

回答by Pekka

You are mixing mysqliand traditional mysqlcommands.

您正在混合mysqli和传统mysql命令。

Use $result->fetch_array().

使用$result->fetch_array().

回答by Nabab

You're using two different sets of functions... mysqli and mysql.
I think you want to use the fetch_assoc() method.

您正在使用两组不同的函数... mysqli 和 mysql。
我认为您想使用 fetch_assoc() 方法。

Check out http://php.net/manual/en/book.mysqli.php

查看http://php.net/manual/en/book.mysqli.php