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
warning:mysql_fetch_array() expects parameter 1 to be resource, object given
提问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_array
instead of mysql_fetch_array
.
您在代码中混合了 mysql 和 mysqli 调用。使用mysqli_fetch_array
代替mysql_fetch_array
。
回答by Pekka
You are mixing mysqli
and traditional mysql
commands.
您正在混合mysqli
和传统mysql
命令。
回答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