This is 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;
}
}
?>
And this is main php file:
<?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();
?>
When I run main php file I see this error:
Fatal error: Using $this when not in object context in C:\AppServ\www\ilk\class\header.class.php on line 19
Line 19:
$query = mysql_query($sql,$this->baglan);
Where is the problem? I can't see problem becuase I'm not writing php code for so long.
mysql_*functions. They are no longer maintained and community has begun the deprecation process. Instead you should learn about prepared statements and use either PDO or MySQLi. If you care to learn, here is a quite good PDO-related tutorial.