設(shè)計(jì)一張瀏覽文章表,字段用自增id、文章id、用戶id、瀏覽時(shí)間、ip、客戶端信息。。。
成都創(chuàng)新互聯(lián)是專業(yè)的祁縣網(wǎng)站建設(shè)公司,祁縣接單;提供成都網(wǎng)站制作、做網(wǎng)站,網(wǎng)頁設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行祁縣網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來合作!
用戶每訪問一次文章就向表中添加一條數(shù)據(jù)
查詢某文章瀏覽量就是select count(*) from 瀏覽表 where 文章id=:id
查詢某文章用戶總量 select count(*) from 瀏覽表 where 文章id=:id group by 用戶id
你做好程序以后,把數(shù)據(jù)庫導(dǎo)出成sql文件
1、連接數(shù)據(jù)庫
2、讀取這個(gè)sql文件里的sql語句,并執(zhí)行
3、生成一個(gè)數(shù)據(jù)庫連接參數(shù)的php文件
?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
if (mysql_query("CREATE DATABASE my_db",$con))
{
echo "Database created";
}
else
{
echo "Error creating database: " . mysql_error();
}
mysql_close($con);
?
?php
class ReadSql {
//數(shù)據(jù)庫連接
protected $connect = null;
//數(shù)據(jù)庫對象
protected $db = null;
//sql文件
public $sqlFile = "";
//sql語句集
public $sqlArr = array();
public function __construct($host, $user, $pw, $db_name) {
$host = empty($host) ? C("DB_HOST") : $host;
$user = empty($user) ? C("DB_USER") : $user;
$pw = empty($pw) ? C("DB_PWD") : $pw;
$db_name = empty($db_name) ? C("DB_NAME") : $db_name;
//連接數(shù)據(jù)庫
$this-connect = mysql_connect($host, $user, $pw) or die("Could not connect: " . mysql_error());
$this-db = mysql_select_db($db_name, $this-connect) or die("Yon can not select the table:" . mysql_error());
}
//導(dǎo)入sql文件
public function Import($url) {
$this-sqlFile = file_get_contents($url);
if (!$this-sqlFile) {
exit("打開文件錯誤");
} else {
$this-GetSqlArr();
if ($this-Runsql()) {
return true;
}
}
}
//獲取sql語句數(shù)組
public function GetSqlArr() {
//去除注釋
$str = $this-sqlFile;
$str = preg_replace('/--.*/i', '', $str);
$str = preg_replace('/\/\*.*\*\/(\;)?/i', '', $str);
//去除空格 創(chuàng)建數(shù)組
$str = explode(";\n", $str);
foreach ($str as $v) {
$v = trim($v);
if (empty($v)) {
continue;
} else {
$this-sqlArr[] = $v;
}
}
}
//執(zhí)行sql文件
public function RunSql() {
foreach ($this-sqlArr as $k = $v) {
if (!mysql_query($v)) {
exit("sql語句錯誤:第" . $k . "行" . mysql_error());
}
}
return true;
}
}
//范例:
header("Content-type:text/html;charset=utf-8");
$sql = new ReadSql("localhost", "root", "", "log_db");
$rst = $sql-Import("./log_db.sql");
if ($rst) {
echo "Success!";
}
?
可以參看discuz數(shù)據(jù)庫表帖子,和帖子附件的設(shè)計(jì),我的大概思路是這樣的:
首先建立一個(gè)數(shù)據(jù)表"film"用來保存簡短文字信息,其中包含:電影發(fā)布時(shí)有名字,主演,簡介,歸屬欄目,發(fā)布電影的URL鏈接。在創(chuàng)建一個(gè)表(考慮到是小型網(wǎng)站,如果中型的話,可以選擇10個(gè),像discuz一樣)"attachement",用來保存,上傳截圖,上傳視頻。這個(gè)表用一個(gè)外鍵與film表連接。中間在外鍵上加索引。
希望我的回答對你有幫助!
使用EclipsePHP Studio 3 創(chuàng)建一個(gè)PHP工程名稱為test1,在工程名下面userinfo的文件夾,然后在文件夾創(chuàng)建一個(gè)PHP文件(userinfo_create.php):
2
打開我們創(chuàng)建PHP文件:
先設(shè)置 地址,賬號,密碼:
$url = "127.0.0.1";//連接數(shù)據(jù)庫的地址
$user = "root"; //賬號
$password = "root";//密碼
//獲取連接$con = mysql_connect($url,$user,$password);
if(!$con){
die("連接失敗".mysql_error());
}
3
設(shè)置具體連接的數(shù)據(jù),那我們這兒連接test數(shù)據(jù)庫,我們通過Navicat 打開mysql 數(shù)據(jù)庫
mysql_select_db("test");
名稱欄目:php如何設(shè)計(jì)數(shù)據(jù)庫 php如何設(shè)計(jì)數(shù)據(jù)庫表
地址分享:http://www.chinadenli.net/article34/dddhgpe.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供響應(yīng)式網(wǎng)站、網(wǎng)站內(nèi)鏈、外貿(mào)建站、商城網(wǎng)站、定制網(wǎng)站、手機(jī)網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)