这是 dbconnect.class.php:
<?php
class Connect
{
public $error;
protected $db;
public function __construct()
{
$link = mysql_connect("localhost","root","1") or $this->error = mysql_error();
$db = mysql_select_db("tarih",$link);
$this->db = $db;
}
}
?>
这是主要的 php 文件:
<?php
//header.class.php
require_once 'dbconnect.class.php';
class Header extends Connect
{
public $headers = array();
private $baglan;
public function __construct()
{
/*
* Bu sınıf sayfaların header bilgilerini işler.
*/
$baglan = $this->db;
}
public function sayfaHeader($sayfa = true)
{
$sql = "SELECT * FROM header WHERE id='" . $sayfa . "'";
$query = mysql_query($sql,$this->baglan);
}
}
Header::sayfaHeader();
?>
当我运行主 php 文件时,我看到此错误:
Fatal error: Using $this when not in object context in C:\AppServ\www\ilk\class\header.class.php on line 19
第 19 行:
$query = mysql_query($sql,$this->baglan);
哪里有问题?我看不到问题,因为我很久没有写 php 代码了。