php 警告:mysql_query() 期望参数 2 为资源
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16433383/
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_query() expects parameter 2 to be resource
提问by Clucky
I am currently experiencing issues with the following script. Upon execution of the script, I do recieve the message "Connection was OK!" however, then I also receive the following messages:
我目前遇到以下脚本的问题。执行脚本后,我确实收到消息“连接正常!” 但是,我也会收到以下消息:
Warning: mysql_query() expects parameter 2 to be resource, object given in /opt/lampp/htdocs/worldofclucky.net/scripts/auth.php on line 11
Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in /opt/lampp/htdocs/worldofclucky.net/scripts/auth.php on line 12
警告:mysql_query() 期望参数 2 是资源,对象在第 11 行的 /opt/lampp/htdocs/worldofclucky.net/scripts/auth.php 中给出
警告:mysql_fetch_array() 期望参数 1 是资源,在第 12 行的 /opt/lampp/htdocs/worldofclucky.net/scripts/auth.php 中给出空值
Any idea what I am doing wrong? I am far from a PHP/MySQL expert, I wouldn't really even consider my self a novice... I did do some testing and the $username variable is sending from the previous page correctly and when typing SELECT * FROM forum.mybb_users WHERE username = 'x_clucky' LIMIT 1into the MySQL client, it gives all of the information you would expect to get. The PHP code is as follows:
知道我做错了什么吗?我远不是 PHP/MySQL 专家,我什至不认为自己是新手......我确实做了一些测试,并且 $username 变量从上一页正确发送,并且在输入SELECT * FROM forum.mybb_users WHERE username = 'x_clucky' LIMIT 1MySQL 客户端时,它提供您期望获得的所有信息。PHP代码如下:
<?php
$username=$_POST["username"];
$hashed_password = md5($_POST['password']); /* For MyBB its $mybb->input['password'] */
$con=mysqli_connect("worldofclucky.net","clucky","CENSORED","forum");
// Check connection
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
} else { echo "Connection was OK!\n";}
$query = mysql_query("SELECT * FROM mybb_users WHERE `username` = '$username' LIMIT 1",$con);
$row = mysql_fetch_array($query);
$encrypted_password = md5(md5($row['salt']).$hashed_password);
if($encrypted_password == $row['password']) {
echo "<script>alert('test');</script>";
}
mysqli_close($con);
?>
Thank you in advanced for your help
提前感谢您的帮助
回答by Yogesh Suthar
change mysqlto mysqliand use below kind of query. You can't use mysqland mysqlialtogether.
改变mysql对mysqli以下类型的查询使用。你不能使用mysql和mysqli完全。
$query = mysqli_query($con, "SELECT * FROM mybb_users WHERE `username` = '$username' LIMIT 1");
$row = mysqli_fetch_array($query);
回答by Sabeen Malik
From a quick look it seems like you are using mysqlifunctions to connect and then mysqlfunctions to make the actual query. mysql_* functions are now deprecated.
乍一看,您似乎在使用mysqli函数进行连接,然后使用函数mysql进行实际查询。mysql_* 函数现已弃用。

