错误是:致命错误:调用未定义的函数Connect_DB() 第12行的C:\ wamp \ www \ movie \ movies.php
config.php:
<?php
//error_reporting(0);
class Connection{
private $host = "localhost";
private $username = "root";
private $password = "";
private $db = "movies";
private $connect;
private $q;
function Conn(){
$this->connect = @mysql_connect($this->host, $this->username, $this->password);
return $this->connect;
}
function Select(){
mysql_unbuffered_query('SET NAMES utf8');
return mysql_select_db($this->db);
}
function Query($sql){
$this->q = mysql_query($sql);
return $this->q;
}
function Rows(){
return mysql_num_rows($this->q);
}
function Object(){
return mysql_fetch_object($this->q);
}
}
?>
movies.php:
<?php
class Movies{
function Connect_DB(){
$data = new Connection;
if(!($data->Conn())) header("Location: 404.php");
if(!($data->Select())) header("Location: 404.php");
return $data;
}
function getImdb(){
$q = "SELECT * FROM top250";
$data = Connect_DB();
$ch = $data->Query($q);
if($ch){
$i=0;
while($r = $data->Object()){
$result["name"][$i] = $r->name;
$result["genre"][$i] = $r->genre;
$result["imdb"][$i] = $r->imdb;
$result["year"][$i] = $r->year;
$result["releaseDate"][$i] = $r->releaseDate;
$result["country"][$i] = $r->country;
$result["imgPath"][$i] = $r->imgPath;
$i++;
}//while
return $q;
}else{
$result = false;
return $result;
}//else
}//getImdb
}
?>
这是html文件:
<?php
require "config.php";
require "movies.php";
$imdb = new Movies;
$result = $imdb->getImdb();
?>
<!DOCTYPE HTML>
<html>
<head>
.....
我找不到错误的位置?我有2个类(config.php和movies.php)Config.php有mysql连接设置,电影从mysql获取一个表,html文件包含2个文件和show table。有人能帮助我吗?
答案 0 :(得分:0)
您没有正确调用CONNECT_DB。在一个类中,当你想调用另一个方法时,我们使用$ this-&gt; method()。因此,将行$data = Connect_DB();
更改为$data = $this->Connect_DB();