Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Created by PhpStorm.
- * User: 1
- * Date: 01.09.14
- * Time: 22:49
- */
- abstract class AbstractModel
- {
- static protected $table;
- static protected function getDbh() {
- $dsn = 'mysql:dbname = articles:host = localhost';
- $res = new Pdo($dsn, 'root', '');
- if (false !== $res) {
- echo 'БД подключена';
- }
- else {
- echo 'Ошибка соединения с БД';
- }
- return $res;
- }
- static public function findAll() {
- $sql = "SELECT * FROM :table";
- $sth = self::getDbh()->prepare($sql);
- //var_dump($sth); die;
- $sth -> execute(array(':table' => static::$table));
- var_dump($sth->fetchAll());
- die;
- //return $sth->fetchAll();
- }
- }
- <?php
- /**
- * Created by PhpStorm.
- * User: 1
- * Date: 02.09.14
- * Time: 9:21
- */
- class Article extends AbstractModel
- {
- static protected $table = 'text';
- //$news = Article::findAll();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement