im studing php :) In first, sorry for my bad english, I try speak normaly :)
I always start writing some code with database, but all time have problems with extends. Please help me.
index.php
define('CWM', TRUE);
define('DS', DIRECTORY_SEPARATOR);
define('PATH', dirname(__FILE__) . DS);
define('LINK', dirname($_SERVER['SCRIPT_NAME']));
require_once 'classes' . DS . 'database.php';
require_once 'classes' . DS . 'session.php';
require_once 'classes' . DS . 'core.php';
$core = new core;
core.php must including session and dbconnection class
if(!defined('CWM')) die('script access error');
class core extends session{
protected $db;
function __construct(){
$this->db = new dbconnection();
parent::session();
}
}
database.php class where i tried connect to database
class dbconnection{
protected $db;
protected $dbinfo = array();
public function connect(){
if(file_exists(PATH . 'classes' . DS . 'config.php')){
$this->dbinfo = require_once PATH . 'classes' . DS . 'config.php';
try{
$this->db = new PDO('mysql:host=' . $this->dbinfo['hostname'] . ';dbname='. $this->dbinfo['dbname'], $this->dbinfo['username'], $this->dbinfo['password'], array(PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC));
return $this->db;
}catch(PDOException $e){
die($e->getMessage());
}
}else{
trigger_error('undefined config.php', E_USER_ERROR);
}
}
function __destruct(){
$this->db = NULL;
}
}
session.php this class tri select information from my bd if user have a session cookie
if(!defined('CWM')) die('script access error');
class session extends dbconnection{
protected $db;
protected $member = array();
function __construct(){
parent::connect();
$this->session;
}
protected function session(){
$_COOKIE['session'] = 5;
if(!empty($_COOKIE['session'])){
$this->member = $this->db->prepare("SELECT * FROM `users` WHERE `session` = '?'")->execute(array($_COOKIE['session']));
var_dump($this->member);
}else{
$this->member = false;
}
}
}
if this posible, i need that core class includes session and database classes, and thes session class included database and core classes