0
使用PHP和MySQL我試圖建立自己的CMS,但下面的教程,我得到這個代碼
在cms_class.php時
<?php
class modernCMS{ //starts class
var $host;
var $username;
var $password;
var $db;
function connect(){
$con= mysql_connect( $this -> host, $this->username, $this->password);
mysql_select_db($this->db, $con) or die (mysql_error()) ;
}// ends function
function get_content(){
$query= "SELECT *
FROM cms_content ORDER BY id DESC";
$result= mysql_query($$query);
while($row= mysql_fetch_assoc($res)){
echo '<h1>' . $row['title'] . '</h1>';
echo '<p>' . $row['body'] . '</p>';
}
}
} //Ends class
?>
然後我的索引頁上我有(PHP第一)
<?php
include '_class/cms_class.php';
$obj= new modernCMS();
//set up connection variables
$obj->host='localhost';
$obj->username='root';
$obj->password='';
$obj->db='modernCMS';
//Connection to the DB
$obj->connect();
?>
那麼php來得到我的cms_content表中的內容是
<?=$obj-> get_content()?>
,當我的本地主機服務器我得到這些錯誤上運行....
未定義的變量cms_class.php線18 mysql_fetch_assoc()
modernCMS-> get_content我的索引。 php line 34
爲什麼不能正常工作?