致命错误:未捕获错误:调用/opt/lampp/htdocs/apms/class/news.php中未定义的方法Dbconnection :: prepare()

时间:2019-04-23 09:12:15

标签: php pdo

当我调用PDO函数时,它向我显示此错误:

  

致命错误:未捕获错误:调用未定义的方法Dbconnection :: prepare()
  在/opt/lampp/htdocs/apms/class/news.php:18
中   堆栈跟踪:
  #0 /opt/lampp/htdocs/apms/class/news.php(30):新闻-> fetch_news_content()
  #1 {main}在第18行的/opt/lampp/htdocs/apms/class/news.php中抛出

这是我的联系班:

class Dbconnection
{
    private $servername = "localhost";
    private $username = "root";
    private $password = "";
    protected $conn;
    public function connect()
    {
        try {
            $conn = new PDO("mysql:host=$this->servername;dbname=apms", $this->username, $this->password);
            $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            return $this->conn;
        } catch (PDOException $e) {
            echo "Connection failed: " . $e->getMessage();
        }
    }
}

0 个答案:

没有答案