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.
It calls method without object creation. You have to do this
If you want to call class’s method then declare method as
static. But you cant use$thisreference because static methods and memebers haven’t reference on class object.UPDATE:
mysql_select_dbreturnsboolvalue. You have to use your$linkvariable for querying.