Здравствуйте, возникла проблема которую я так и не могу решить, задавал подобный вопрос на другом форуме но там так же мне не помогли. Иметься следующий код. Файл Core.php Код | <? Class Core extends Core_Template //Получаем id пользователя public function user_id() { if(isset($_SESSION['userid'])) { return $_SESSION['userid']; } else { return 0; } } //Проверяем аутентификацию пользователя public function checkAuth() { $result = $this->sqlQuery("Select count(*) from user where id = ':param1'", $this->user_id()); if($result['count(*)'] > 0) { return true; } else { return false; } } //Подключаемся и пользуеся базой данных public function sqlQuery($text, $param1 = "", $param2 = "", $param3 = "", $param4 = "") { $sql = $this->db->prepare($text); for ($i = 1; $i <= 4; $i++) { if($i == 1 && $param1 != "") { $sql->bindParam(':param1', $param1, PDO::PARAM_STR); } if($i == 2 && $param2 != "") { $sql->bindParam(':param2', $param2, PDO::PARAM_STR); } if($i == 3 && $param3 != "") { $sql->bindParam(':param3', $param3, PDO::PARAM_STR); }if($i == 4 && $param4 != "") { $sql->bindParam(':param4', $param4, PDO::PARAM_STR); } } $sql->execute(); return $sql->fetch(); } } ?>
|
Файл Core_Templayte Код | <? class Core_Template extends BaseModule { private $jsinc; private function html() { $result = '<!DOCTYPE HTML> <head> <meta http-equiv= "Content-Type" content="text/html; charset=utf-8"> <title>CHATER</title>'; return $result; } private function head() { $result .= '<link rel="stylesheet" href="Styles/Style.css" type="text/css" media="screen" />'; $result .= '<script type="text/javascript" src="/?link=js/jquery-3.1.1.js"></script>'; $result .= '<script type="text/javascript" src="/?link=Core/Core.js"></script>'; $result .= $this->jsinc; $result .= '</head>'; return $result; } private function body() { $result = '<body> <div class="head"> <Span class="logo"><a href="./">CHATER</a></span>'; if($this->checkAuth()) { $result .=' <div class="setting"> <a href="#" class="showHelp"><img src="img/setting.png"></a> <div class="help" style="display:none"> <a href="#" class="checkProfile" id = "'.$this->user_id().'">Профиль</a><br/> <a href="#" class="exit">Выход</a> </div> </div>'; } $result .='</div>'; return $result; } private function footer() { $result = '</body> </html>'; return $result; } public function addjsfile($page) { $this->jsinc .= '<script src="/?link='.$page.'.js" type="text/javascript"></script>'; } public function show($html, $page) { addjsfile($page); return $this->html().$this->head().$this->body().$html.$this->footer(); } }
|
Файл BaseModule Код | <? abstract class BaseModule { protected $db; public function __construct() { global $host; global $base; global $user; global $pass; try { $this->db = new PDO('mysql:host='.$host.'; dbname='.$base.'', $user, $pass); $this->db->exec("SET NAMES UTF8"); } catch (PDOException $e) { die ('База данных временно недоступна '.$e); } } public function __get($value) { if ($value=='db') return $this->db; return NULL; } } ?>
|
Файл Test_Template Код | <? Class test_Template extends test { public function index() { $result = ' <div class="main"> <div class="content front"> <h3>Авторизация</h3> <form method="post" id="auths"> <input type="text" name="login" id="login_auth" placeholder="логин"/> <input type="password" name="password" id="pass_auth" placeholder="Пароль"/><br/> <input type="submit" name="button" id="auth" value="Авторизоваться" /><br/> <a href="#" class="recovery">Забыли пароль?</a></br> <hr/><span class="or"> Или </span><hr/> <a href="#" class="Regestration" id="flip">Зарегистрируйтесь</a> </form> </div> <div class="content back"> </div> </div>'; return $this->show($result, "Main"); } ?>
|
Файл test Код | <? class test extends Core { public function testFunc() { $result = $this->sqlQuery("Select test from table where id = ':param1'", $this->user_id()); return $result['test']; } } ?>
|
Файл index Код | include_once ('config.php'); include_once ('BaseModule.php'); include_once ('Core_Template.php'); include_once ('Core.php'); include_once ('test_Template.php');
$test = new test_Template; echo $test->index();
|
В результате получаю ошибку Цитата | Fatal error: Call to a member function prepare() on a non-object in X:\home\site\www\Core.php on line 129
|
Возвещает Null Если произвести вызов так Файл index Код | include_once ('config.php'); include_once ('BaseModule.php'); include_once ('Core_Template.php'); include_once ('Core.php'); include_once ('test_Template.php');
$test = new Core_Template; echo $test->show('test', 'Test');
|
То не какой ошибки нет Выдает Цитата | object(PDO)#1 (0) { }
|
|