致命错误:未被捕获的错误:调用未定义的函数dbconnect()

时间:2019-03-05 13:58:03

标签: php database

我是新来的。我正在开发的网站存在问题。您能帮我解决这个问题吗?

错误-

  

致命错误:未捕获错误:调用未定义函数dbconnect()   /storage/ssd4/448/8893448/public_html/blog/index.php:5堆栈跟踪:#0   {main}丢在/storage/ssd4/448/8893448/public_html/blog/index.php中   在第5行

这里是.php连接

<?php

class connection{

    public $db_host = 'localhost';
    public $db_name = 'id8893448_ifians';
    public $db_user = 'id8893448_ifdb';
    public $db_pass = 'admin';

    public function dbconnect()
    {
        try{
            $conn = new PDO("mysql:host=".$this->db_host.";dbname=".$this->db_name,$this->db_user,$this->db_pass);
           $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        }
        catch(PDOException $e)
        {
            echo 'ERROR: ' . $e->getMessage();
        }    
        return $this->conn;
    }
}

?>

和index.php

<?php

include 'functions/connect.php';
include 'functions/queries.php';
$conx = dbconnect();
$recentArray = Array();
$recent = recents() ;
$resultRecent = mysqli_query($conx, $recent);
$blogPost = Array();
while($rowRecent = mysqli_fetch_assoc($resultRecent)) {
    array_push($recentArray, $rowRecent);
};

//var_dump($recentArray);



$selectTitle = selectTitle();
//print_r($selectTitle);

$selectAuthor = selectAuthor();
$selectDate = selectDate();

$selectTitleArray = Array();
$selectAuthorArray = Array();
$selectDateArray = Array();

$selectTitleResult = mysqli_query($conx, $selectTitle);
$selectAuthorResult = mysqli_query($conx, $selectAuthor);
$selectDateResult = mysqli_query($conx, $selectDate);

while($selectTitleRow = mysqli_fetch_assoc($selectTitleResult)) 
{
    array_push($selectTitleArray, $selectTitleRow);
};

while($selectAuthorRow = mysqli_fetch_assoc($selectAuthorResult)) 
{
    array_push($selectAuthorArray, $selectAuthorRow);
};

while($selectDateRow = mysqli_fetch_assoc($selectDateResult)) 
{
    array_push($selectDateArray, $selectDateRow);
};
//print_r($selectTitleArray);






if (isset($_GET['query']))
{
    $blog = modifiedQuery($_GET['query'],$_GET['value']);
}

elseif (isset($_GET['title']) || isset($_GET['author']) || isset($_GET['created']))
{
    $blog = submitQuery($_GET['title'],$_GET['author'],$_GET['created']);
}
else 
{   
        $blog = originalQuery();
}

//print_r($blog);

$result = mysqli_query($conx, $blog);

//print_r($result);

while($row = mysqli_fetch_assoc($result)) 
{
    array_push($blogPost, $row);
};



include 'templates/template.php';


?>

1 个答案:

答案 0 :(得分:1)

您需要创建connection类的实例,然后可以使用该实例来调用其dbconnect函数

$newcon = new connection();
$conx = $newcon->dbconnect();