我想切换mysql_*到mysqli_*因为我读过,很快mysql_*就不再支持了.
现在我有一个问题,我写的功能不再适用了.
在我的index.php文件中
global $connect;
$connect = mysqli_connect('localhost', "username", "password");
Run Code Online (Sandbox Code Playgroud)
在我有的functions.php文件中
function count_total_messages(){
$result = "SELECT COUNT(id) AS total FROM database.messages WHERE uidto='".$_SESSION['userid']."' OR unameto='".$_SESSION['username']."'";
$qry = mysqli_query($connect,$result);
return $qry['total'];
}
Run Code Online (Sandbox Code Playgroud)
但是我收到以下错误:
未定义的变量:连接
我该怎么办?mysqli_query除了来自functions.php文件的那些工作以外的所有地方.