示例#1
0
 public function __construct($table)
 {
     header('Content-type:text/html;chartset=utf-8');
     $config_db = config('db');
     $this->table = $config_db['db_table_prefix'] . $table;
     $this->db = mysql::getInstance($config_db);
 }
示例#2
0
文件: user.php 项目: ztaoge/blog
 protected function init()
 {
     $this->_dbh = mysql::getInstance();
     $results = $this->_dbh->select('blog_users', ['username' => $this->username]);
     $this->id = $results[0]['id'];
     $this->create_time = $results[0]['create_time'];
     $this->email = $results[0]['email'];
     $this->avatar = $results[0]['avatar'];
     $this->user_group = $results[0]['user_group'];
 }
示例#3
0
文件: signup.php 项目: ztaoge/blog
function check_username()
{
    $dbh = mysql::getInstance();
    $username = $dbh->select('blog_users', ['username' => $_GET['username']]);
    if ($username) {
        //该用户已存在
        echo 201;
    } else {
        //该用户不存在
        echo 404;
    }
}
示例#4
0
文件: page.php 项目: ztaoge/blog
 public function test()
 {
     $this->_dbh = mysql::getInstance();
     return self::$results = $this->_dbh->select($this->_table, [], [], 'create_time', 'DESC');
 }
示例#5
0
文件: signin.php 项目: ztaoge/blog
<?php

require 'vendor/mysql.php';
require 'common/config/conf.php';
isset($_POST['username']) ? $username = $_POST['username'] : ($username = null);
isset($_POST['passwd']) ? $passwd = $_POST['passwd'] : ($passwwd = null);
if ($username && $passwd) {
    $dbh = mysql::getInstance();
    if ($result = $dbh->select('blog_users', ['username' => $username, 'passwd' => $passwd])) {
        setcookie('username', $username, COOKIE_EXPIRE);
        // 10s
        echo 'success';
    } else {
        echo 'fail';
    }
}
<?php

error_reporting(0);
include 'simple_html_dom.php';
include 'mysql.class.php';
define('ENV', 'debug');
$config = ['charset' => 'utf8', 'db' => 'test', 'table' => 'films', 'debug' => ['host' => 'localhost', 'user' => 'user', 'password' => 'password', 'port' => '3306']];
$mysql = mysql::getInstance();
$mysql->connect($config);
for ($parm = 0; $parm <= 225; $parm += 25) {
    $url = 'http://movie.douban.com/top250?start=' . $parm . '&filter=&type=';
    $html = file_get_contents($url);
    $dom = new simple_html_dom($html);
    $listData = $dom->find('#content .item');
    foreach ($listData as $key => $val) {
        $film = ['title' => rtrim($val->find(".title", 0)->plaintext), 'subtitle' => str_replace(['&nbsp', ';/;'], '', $val->find(".title", 1)->plaintext), 'link' => $val->find("img", 0)->parent->attr['href'], 'img' => $val->find("img", 0)->src, 'rate' => $val->find('.star em', 0)->plaintext, 'quote' => $val->find(".quote .inq", 0)->plaintext];
        $mysql->data($film)->add();
        echo $film['title'] . ' -- ' . $film['quote'] . PHP_EOL;
    }
}
//
示例#7
0
文件: user.php 项目: ztaoge/blog
<?php

require_once 'asset/smarty-3.1.28/libs/Smarty.class.php';
require_once 'common/config/conf.php';
require_once 'vendor/mysql.php';
require_once 'vendor/page.php';
require_once 'common/smarty.inc.php';
isset($_COOKIE['username']) ? $username = $_COOKIE['username'] : ($username = null);
if (is_null($username)) {
    $smarty->display('error.html');
} else {
    $users = mysql::getInstance()->select('blog_users', ['username' => $username]);
    $comments = mysql::getInstance()->select('blog_comments', ['comment_author' => $username]);
    $posts = mysql::getInstance()->select('blog_posts', ['post_author_id' => intval($users[0]['id'])]);
    $friends = mysql::getInstance()->select('blog_friends', ['user_id' => intval($users[0]['id'])]);
    $smarty->assign('posts', $posts);
    $smarty->assign('friends', $friends);
    $smarty->assign('comments', $comments);
    $smarty->assign('users', $users);
    $smarty->assign('username', $username);
    $smarty->display('user.tpl');
}
示例#8
0
文件: postlist.php 项目: ztaoge/blog
<?php

require_once 'asset/smarty-3.1.28/libs/Smarty.class.php';
require_once 'common/config/conf.php';
require_once 'vendor/mysql.php';
require_once 'vendor/page.php';
require_once 'common/smarty.inc.php';
isset($_COOKIE['username']) ? $username = $_COOKIE['username'] : ($username = null);
//每页默认数据量
$num = 5;
$username = mysql::getInstance()->select('blog_users', ['username' => $username]);
$posts = mysql::getInstance()->select('blog_posts', ['post_author_id' => intval($username[0]['id'])]);
$page = new page('blog_posts', [], $num, 'create_time');
isset($_GET['page']) ? $p = $_GET['page'] : ($p = 1);
$list = $page->getPage($p);
$smarty->assign('list', $list);
$smarty->assign('page', $p);
$smarty->assign('tag', $page->getTag($p));
$smarty->assign('total', $total = $page->tt());
$smarty->assign('username', $username[0]['username']);
//$smarty->assign();
if ($username) {
    $smarty->display('postlist.tpl');
}