如何更正我在我的功能中出现的错误,以下是我的错误
Warning: mysql_query() expects parameter 2 to be resource, null given in C:\xampp\htdocs\how are things\15_06_widget_corp-final\includes\functions.php on line 40
Database query failed:
第40行的代码就是这个
$subject_set = mysql_query($query, $connection);
这是我的功能代码
function get_all_subjects($public = true) {
global $connection;
$query = "SELECT *
FROM subjects ";
if ($public) {
$query .= "WHERE visible = 1 ";
}
$query .= "ORDER BY position ASC";
$subject_set = mysql_query($query, $connection);
confirm_query($subject_set);
return $subject_set;
}
答案 0 :(得分:0)
它需要$connection
来引用与mysql服务器的连接
试试
$connection = mysql_connect('host','user','pass');
答案 1 :(得分:0)