致命错误:调用未定义的方法ConnectDatabase :: query()

时间:2016-12-11 23:05:16

标签: php mysql mysqli

我创建了一个OOP-PHP脚本,我得到了关注消息,我不明白为什么???

致命错误:在第73行调用未定义的方法ConnectDatabase :: query()....

我的PHP代码

<?php

class ConnectDatabase {

private $host = 'localhost';
private $username = 'root';
private $password = '';
private $database = 'database';
private $db_connection;
private $db_query;

//Connect Database.
  function __construct() {
  $this->open_db();
}

public function query($sql) {
 $this->db_query = query($sql, $this->db_connection);
}

public function open_db() {

$this->db_connection = new mysqli($this->host, $this->username, $this->password);

if (is_resource($this->db_connection)) {
  die("Error!");
 } else {
  $this->db_connection->select_db($this->database) or die('Error');
  }
 }
}

$dbConnection = new ConnectDatabase();

class GetContent {

 public function newContent() {
 global $dbConnection;
 $sql = "SELECT * FROM mytable";
 // ----- This Line make an Error ------
 $query = $dbConnection->query($sql);
 $found = $dbConnection->fetch_array($query);
 return $found;
 }
}

如果您有任何想法,请帮助。

0 个答案:

没有答案