未能在不出错的情况下将函数从一个PHP文件调用到另一个文件


Failing to call a function from one PHP file to the other without getting errors

我正试图将数据库中的一些数据调用到我正在制作的应用程序中,但遇到了一个小问题。

文件:Dbconnect.php

<?php
connect();
function __destruct() {
    $this->close();
}
function connect() {
    require_once __DIR__ . '/Config.php';
    $con = mysql_connect(DB_HOST, DB_USERNAME, DB_PASSWORD) or     die(mysql_error());
    $db = mysql_select_db(DB_NAME) or die(mysql_error()) or die(mysql_error());
    return $con;
}
function close() {
    mysql_close();
}
?>

文件:Get_Subjects.php

<?php
require_once 'Dbconnect.php';
function getSubjects(){
    $db = new connect();
?>

当我尝试调用connect()时;函数,则会出现以下错误:

PHP致命错误:在第6行的G:''PleskVhosts''opuna.co.uk''httpdocs''subject_api''Get_Subjects.PHP中找不到类"connect"

我不知道为什么这种情况一直在发生。

connect()是一个函数,而不是一个类。所以你只需要在没有new 的情况下调用它

function getSubjects(){
    $db = connect();
?>