1.php的代碼,必須放在.php的文件中,php代碼必須寫在<?php ?>之間。php
2.//單行註釋 /* 多行註釋 */css
3.默認首頁index.php index.html index.htm,優先級從左到右。
在Apache的配置文件裏設置
<IfModule dir_module>
DirectoryIndex index.php index.html index.htm
</IfModule>html
4.若是是個純php頁面,那麼最後的?>能夠不寫,也最好別寫。mysql
<?php
5.
$name='tudou';
echo '{$name}';正則表達式
6.變量名區分大小寫,函數名不區分大小寫sql
7.變量輸出:
echo($name); //輸出變量
var_dump($name); //輸出數組,而且打印類型和長度,訪問同一個元素3次後會中止
print_r($name); //輸出數組數據庫
8.變量用法:
a.普通變量 $name='aaa';
b.可變變量
$name='aaa';
$$name='bbb';
c.變量引用
$a=10;
$b=&$a; //把$a的內存地址給了$b,那麼修改$b的值,$a的確定也被修改
$b=20;
echo $a;
echo "<br>";
echo $b;
20
20數組
$a=$b 是把$b的值賦給$a
$a=&$b 是把$b的地址給$a瀏覽器
9.php變量類型:
a.整型 // php中,3/2 = 1.5
b.浮點型
c.字符串
d.布爾型 // 2=="2" 真。等於。不判斷類型。 2==="2" 假。全等於。判斷類型。
//以上四種類型是標量
e.數組
f.對象 // 對象由兩部分組成:特種和功能,在程序中叫屬性和方法。
//以上兩種是複合類型
g.資源
h.null
//以上兩種是特殊類型服務器
php鏈接符是.不是+
$a='hello';
echo $a.'world';
echo輸出布爾值時,true會變成1,false會變成空。因此用var_dump()就能夠顯示類型了。
數組:
$arr=array('a','b','c');
echo "<pre>";
print_r($arr);
var_dump($arr);
echo "</pre>";
echo $arr[1];
$arr[]='d'; //會自動日後加一個值
面向對象方法:
<?php
header('content-type:text/html;charset=uft-8'); //在這裏寫header頭,設置編碼。header頭前面不容許有輸出。
class per{
function say(){
echo '<h1>我正在說話!</h1>';
}
function eat(){
echo '<h1>我正在吃飯!</h1>';
}
function sleep(){
echo '<h1>我正在睡覺!</h1>';
}
}
$user=new Per();
var_dump($user);
$user->eat();
資源
$conn=mysql_connect('localhost','root','123')
$conn2=mysql_connect('localhost2','root','123')
mysql_select_db('test');
mysql_query('set names utf8');
$sql='select * from user';
$rst=mysql_query($sql);
while ($row=mysql_fetch_assoc($rst)) {
echo '<h1>ID:{$row['id']}</h1>';
echo '<h1>Name:{$row['name']}</h1>';
# code...
}
mysql_query('查看數據庫',$conn2);
//$conn和$conn2是鏈接數據庫資源
10.isset和empty兩個函數的區別:
isset 變量是否存在
不存在:
a.沒有定義
b.null
$name='user1';
var_dump(isset($name));
empty 變量是否爲空
爲空:
a.0
b.""
c."0"
d.false
e.array()
f.null
g.沒有定義
11.類型測試
變量類型測試
a.整型 is_int();
b.浮點型 is_float();
c.字符串 is_string();
d.布爾型 is_bool();
e.數組 is_array();
f.對象 is_object();
g.資源 is_resource();
h.null is_null();
is_scalar(); //測試是不是標量(整型、浮點型、字符串、布爾型)
is_numeric(); //測試是不是數字(整型、浮點型)
is_callable(); //測試是不是函數,而不是語言結構
經常使用的語言結構:
a.echo();
b.print();
c.array();
d.list();
……
12.類型自動轉換-標量
a.整型 --> 字符串
$num = 123;
echo $num.'abc';
b.字符串 --> 整型
$str='123';
echo $str+1;
c.其餘類型 --> 布爾型
a.0
b.""
c."0"
d.false
e.array()
f.null
g.沒有定義
//以上都爲false,其他爲真
$num=0;
if($num){
}
var_dump($num);
13.類型強制轉換-標量
(int)$num
(float)$num
(string)$num
……
14.字符串的單雙引號
$str1='hello';
$str2='world';
echo $str.' '.$str2;
echo '我是{$str1},我想……';
//單引號比雙引號的執行速度要快得多,可是,在單引號中,變量沒法被解析。這也是單引號比雙引號快的緣由。
//字符串中沒有變量須要解析就用單引號,不然就用雙引號或者單引號(用.鏈接)
15.刪除變量
$name="user1";
unset($name)
var_dump(isset($name));
16.常量的定義:
//跟變量同樣,可是一旦被定義就不能被修改
define('HOST', 'localhost'); //前面是名字,後面是值
define('USER', 'root');//
//好比數據庫鏈接的配置文件,這個時候就要用常量,並且後面不能被修改。
<?php
include('config.inc.php');//加載同目錄下的配置文件。
echo 'my host is '.HOST;//常量不能放到雙引號裏面去
$conn=mysql_connect(HOST,USER,PASS);
$conn2=mysql_connect('localhost2','root','123');
mysql_select_db('test');
mysql_query('set names utf8');
$sql='select * from user';
$rst=mysql_query($sql);
while ($row=mysql_fetch_assoc($rst)) {
echo '<h1>ID:{$row['id']}</h1>';
echo '<h1>Name:{$row['name']}</h1>';
# code...
}
注:mysql中的test數據庫,用root登錄,密碼即便不正確,也能夠匿名登陸!!
17.預約義常量:
PHP_OS //系統平臺
PHP_VERSION //php版本
__LINE__ //常量所在行數
__FILE__ //文件絕對路徑
__FUNCTION__ //顯示函數名
M_PI //圓周率
18.運算符:
a.一元
$num++
$num--
//先賦值後運算
++$num
--$num
//先運算,後賦值
$a=2;
$b=$a++; //先賦值,後運算
$b=++$a;//選運算,後賦值
echo $a;
echo '<br>';
echo $b;
b.二元
+ - * / %
//數學運算符
+= -= *= /= %= //和Python裏的同樣
//賦值運算符
> < >= <= == != === !==
//比較運算符
&& //有開關功能,前面爲真才執行後面
|| //有開關功能,前面爲假才執行後面
!
//邏輯運算符
$a=0;
$b=4;
if($c=($a&&$b=6)){ //$a已是假,因此$b=6不會執行,這就是所謂的開關,走到這裏開關已經關上了。
echo '1';
}else{
echo'2';
}
var_dump($a);
var_dump($b);
var_dump($c);
//輸出值。0,4,false
//
c.三元
?:
$a=3;
if ($a<3) {
$num=3;
# code...
}else{
$num=$a;
}
//以上if語句可簡化以下
$num=$a<3?3:$a;
運算符優先級
@運算符://屏蔽函數報錯
$conn=@mysql_connect('localhost','root','123');
數組運算符:
=>//給數組加字母下標,自定義下標
$arr=array('user1','user2','user3'); //索引數組
$arr=array('name'=>'user1','age'=>'30');//關聯數組(我以爲像字典)
對象運算符:
->
$user->say();
19.流程控制:
分支結構
if ...elseif...else
switch...case
循環控制
for
while
終止循環
break
continue
剩餘部分
a.do...while
d.99乘法表
終止腳本:
b.exit();
c.die();
20.函數
語言結構
自定義函數
變量做用域
靜態函數
函數返回值
參數
默認參數
引用參數
可變個數參數
回調函數
變量函數
遞歸函數
文件包含
函數分類
1.自定義函數
2.回調函數
3.變量函數
4.遞歸函數
語言結構
if();
for();
while();
switch();
echo();
print();
array();
list();
foreach();
isset();
unset();
empty();
exit();
die();
include();
require();
自定義函數:
function fun(){}
調用函數:
fun();
function sum($a,$b){
echo $a+$b;
}
echo "1+2=".sum(1,2);
輸出結果:31+2= //經測試,Python計算方式也是如此,不過會多一個None
函數的結果:
1.輸出結果
2.返回結果
func_num_args();//返回傳入參數的個數
func_get_args();//返回傳入參數的值
array_sum();//計算數列的和
變量函數
function sum($i,$j){
return $i+$j;
}
$a="sum";//變量函數
echo $a(1,2);
$num=10;
function fun(&$i){
$i++;
}
fun($num);//直接在內存地址中計算,因此輸出11
echo $num;
引用參數:
函數內部和函數外部指向同一個變量的地址,改變函數內部的變量值,函數外面也會發生變化
回調函數:
一個函數的參數是另外一個函數的名字,那麼這個參數就叫回調函數
靜態變量:
屢次跟蹤同一個函數,靜態變量能夠一直跟蹤下去
包含文件:
include();//報錯後代碼繼續執行
require();//報錯後終止
遞歸函數:
函數裏面調用本函數
php的執行過程:
1.加載頁面
2.語法檢測(1.語法檢測 2.加載函數)
3.執行腳本
數組:
1.數組定義和遍歷
2.數組函數
數組定義:
$arr=array(1,2,3);//索引數組
$arr=array("name"=>"user1","age"=>30);//關聯數組
數組下標:
$arr=array("name"=>1,2,"age"=>3,4,100=>5,6,5=>7,8);
[name] => 1
[0] => 2
[age] => 3
[1] => 4
[100] => 5
[101] => 6
[5] => 7
[102] => 8
//若是不是自定義下標,下標永遠是上一個數字下標加1.
數組取值:
1.輸出整個數組:
print_r();
2.取某一個值:
echo $arr['arr'];
echo $arr[100];
數組賦值:
$arr['age']=30;//和Python同樣
數組賦值定義數組:
$arr[]=1;
$arr[]=2;
數組遍歷:
1.for循環
2.foreach循環
3.while...list...ecah循環
//推薦使用foreach
for(){
}
//
foreach ($arr as $key=>$val){
echo "<h1>{$key}:{$val}</h1>";
}
//Python裏的遍歷字典
while (list($key,$val)=each($arr)){
echo $key.$val;
//print_r($row);
}
多維數組:
1.一維數組$arr=array(1,2,3);
$arr[0];
2.二維數組$arr=array(1,2,arr(4,5));
$arr[2][0];
3.三維數組$arr=arrar(1,2,array(3,array(4,5)));
$arr[2][1][0];
超全局數組:
$_SERVER
$_GET
$_POST
$_REQUEST
$_FILES
$_COOKIES
$_SESSION
$GLOBALS
$_SERVER 查看服務器信息:
print_r($_SERVER);
$_GET 獲取get提交過來的數據
兩個頁面之間通信
1.表單(get方式 post方式)
2.a標籤傳值(get方式)
a標籤推薦使用get方式提交數據
表單推薦使用post方式提交數據
$_POST
獲取表單post過來的數據
$_REQUEST
獲取a或表單get或post過來的數據 //不建議使用,處理速度慢
$_COOKIE
同一個變量在多個頁面獲取到
$_SESSION
同一個變量在多個頁面獲取到
$_FILES
獲取表單中的文件,並生成一個數組
$GLOBALS
$GLOBALS[SCRIPT_FILENAME]
$GLOBALS[username] //裏面包含頁面內的全局變量,而且經過$GLOBALS[username]="user2"改變$username的值
數組處理函數
1.array_keys();
2.array_values();
3.in_array();
4.array_key_exists();
5.array_flip();
6.array_reverse();
統計數組的元素和惟一性:
1.count
2.array_count_values();
3.array_unique();
使用回調函數處理數組的函數:
1.array_filter();
2.array_map();
引用參數:
需求:數組值自加1
function add($$arr){
foreach ($arr as $key => $value) {
$arr[$key]=$val+1;
}
}
數組的排序函數:
1.sort(); 升序,不保留key
2.rsort(); 降序,不保留key
3.asort(); 升序,保留key
4.arsort(); 降序,保留key
5.ksort(); key排序
6.krsort(); key排序
7.natsort(); 天然排序
8.natcasesort(); 天然排序不區分大小寫
9.array_multisort(); 多數組排序
字符串知識點:
1.字符串的處理介紹
2.經常使用的字符串輸出函數
3.經常使用的字符串格式化函數
4.字符串比較函數
5.正則表達式在字符串中的應用
6.與Perl兼容的正則表達式函數
字符串輸出:
1.echo
2.print
3.printf()
4.sprintf()
字符串鏈接符:
.用點鏈接
去除空格和字符串填補函數:
1.ltrim() //去除左空格
2.rtrim() //去除右空格
3.trim() //去除左右空格
4.str_pad() //返回填充後的字符串
5.str_repeat() //重複一個字符串
6.strlen() //獲取字符串長度
字符串大小寫轉換:
1.strtoupper() //轉大寫
2.strtolower() //轉小寫
3.ucfirst() //行首字母大寫
4.ucwords() //詞首字母大寫
其餘字符串格式化函數:
1.strlen()
2.strrev() //翻轉字符串
3.number_format() //相似貨幣的格式化123,456,789
4.md5() //md5加密
5.str_shuffle() //隨機打亂字符串順序(驗證碼)
與html標籤相關聯的字符串函數
1.nl2br()把\n轉成<br>標籤
2.htmlspecialchars() 轉實體
3.strip_tags() 去掉html標籤,也能夠保留一部分
4.addslashes() 轉義' " \,在他們前面加\,默認php開啓 '
5.stripcslashes() 去掉addslashes前面加的反斜線\
建議在數據庫插入以前進行三道把控
1.標籤過濾
[b]ssssss[/b]
2.addcslashes()
// ' " 前加\防止對數據庫形成破壞
3.htmlspecialchars()
把<>''""轉成實體,防止對數據庫形成破壞
字符串比較函數
1.strcmp(str1, str2) //
2.strcasecmp(str1, str2)
按天然排序法時字符串的比較
1.strnatcmp(str1, str2)
2.strnatcasecmp(str1, str2)
字符串截取
1.substr(string, start)
2.mb_substr(str, start)
查詢字符串位置
1.strstr(haystack, needle)
2.strrchr(haystack, needle)
3.str_replace(search, replace, subject) //替換字符串
字符串拆分經常使用函數:
1.pathinfo(path);
2.parse_url(url);
3.parse_str(str);
正則表達式:
1.原子
2.元字符
3.模式修正符
正則表達式函數
1.preg_match(pattern, subject)
2.preg_match_all(pattern, subject, matches)
3.preg_grep(pattern, input)
4.preg_replace(pattern, replacement, subject)
5.preg_split(pattern, subject)
原子
. 任意一個字符
\w 字母、數字、下劃線
[] 裏面任意一個字符
[^abc] 它裏面除了abc的任意字符
() 一個單元
\d 任意一個數字
\D 任意一個非數字
\w 任意一個字母、數字、下劃線
\W 除了空白字符、數字、下劃線之外任意一個字符
\s 空白字符
\S 除空白字符外的任意字符
有特殊含義的加\
模式修正符
i,m,s,U,e
i 忽略大小寫
m 視爲多行
s 視爲單行
U 貪婪模式,最大化匹配
e 若是設定了此修正符,preg_replace() 在替換字符串中對逆向引用做正常的替換,將其做爲 PHP 代碼求值,並用其結果來替換所搜索的字符串。
元字符
* 0個、1個、多個
+ 1個、多個
? 0個、1個
| 或
^ 開頭
$ 結尾
\b 詞邊緣
\B 非詞邊緣
{m} m個
{n,m} n到m個
{n,} n個前面原子
數學函數
日期函數
錯誤處理
字符串分割
preg_split(pattern, subject)
數學函數
1.max(values)
2.min(values)
3.mt_rand() 隨機數
4.ceil()
5.floor() 地板除
6.pi()
7.rand() 四捨五入
日期函數
1.time(oid)
2.date(format)
3.strtotime(time)
4.microtime() //微秒
microtime(1) 方便參與數學運算
date參數
Y 2013
y 13
m 03
n 3
d 05 號
j 5 號
H 24小時制
h 12小時制
i 05 分鐘
s 05 秒
w 0-6 週日到週六
t 31 一個月天數
L 是否爲閏年
實例:萬年曆
1.幾年幾月幾日
2.週日到週六
3.一號是星期幾
4.這個月有多少天
5.下一年和上一年
6.上一月和下一月
php錯誤處理:
1.關閉和開啓報錯
2.報錯級別
3.報錯地方
關閉和開啓報錯:
display_errors = On
E_ALL //全部錯誤
E_ERROR //嚴重錯誤
E_WARNING //警告錯誤
E_PARSE //語法錯誤
E_NOTICE //提示錯誤
報什麼級別的錯:
error_reporting = E_ALL
E_ALL & ~E_NOTICE 全部,除了notice
display_errors = On //是否從瀏覽器輸出錯誤
log_errors = off //是否把錯誤日誌寫入錯誤日誌
error_log = d:\php.log
gd庫畫圖
1.準備畫布
imagecreatetruecolor(width, height);
2.準備塗料
3.畫畫
4.輸出圖
5.保存圖
6.關閉畫布
圖片處理函數實用場景
1.驗證碼
2.縮放
3.裁剪
4.水印
繪製圖像
imagefill(image, x, y, color) 填充
imageellipse(image, cx, cy, width, height, color) 橢圓
imagesetpixel(image, x, y, color) 點
imageline(image, x1, y1, x2, y2, color) 線
imagerectangle(image, x1, y1, x2, y2, color) 矩形
imagepolygon(image, points, num_points, color) 多邊形
imagearc(image, cx, cy, width, height, start, end, color) 圓弧
imagestring(image, font, x, y, string, color) 字符串
imagechar(image, font, x, y, c, color) 單個字符
imagettftext(image, size, angle, x, y, color, fontfile, text)
php驗證碼設計:
頁面跳轉
1.header('location:index.php');
2.js跳轉
echo "<script>loaction='index.php'</script>";
獲取圖片的寬度
1.getimagesize(filename)
2.imagesx(image)
3.imagesy(image)
已經存在的圖片造成畫布資源
1.imagecreatefromjpeg(filename)
圖片縮放函數
imagecopyresampled(dst_image, src_image, dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h)
圖片等比例縮放
圖片裁剪函數
imagecopyresampled();
圖片水印函數
imagecopy(dst_im, src_im, dst_x, dst_y, src_x, src_y, src_w, src_h)
文件操做
filetype(filename)
is_dir(filename)
is_file(filename)
file_exists(filename) //文件和目錄是否存在
filesize(filename)
unlink(filename) //文件刪除
新建文件 fopen(filename, mode)
刪除文件 unlink(filename)
文件重命名 rename(oldname, newname)
文件複製 copy(source, dest)
文件移動
打開文件 fopen(filename, mode)
讀取文件
寫入文件 fwrite(handle, string)
r+ 擦除寫
w+ 清空寫
關閉文件 fclose(handle)
file(); //把文件以數組返回
readfile(); //拋出文件內容,包括圖片
file_get_contents(); //獲取文件內容
file_put_contents($filename,$str,FILE_APPEND); //寫入文件內容
rewind(handle) //將指針返回文件開頭
feof(); //判斷指針是否到了文件結尾
mkdir(); //建立目錄
rmdir(); //刪除目錄
與路徑有關的函數
basename();
dirname();
pathinfo();
__FILE__; //輸出絕對路徑
realpath(); //當前目錄或者上級目錄的絕對地址
DIRECTORY_SEPARATOR;
PATH_SEPARATOR;
parse_url();
parse_str();
遍歷目錄:
opendir();
文件上傳
1.表單
<from action="upload.php" method='post' ecctype="multipart/form-data">
<input type="file" name="file">
</from>
2.上傳php頁面
move_uploaded_file(filename, destination)
$_FILES['myfile']['error']
0 無錯誤
1 上傳文件大小超過約定值
2 上傳文件大小超過表單限制
3 文件只被部分上傳
4 沒有上傳任何文件
文件下載
header("content-type:application/octet-streame");
header("content-disposition:attachment;filename={$imgfile}");
header("content-lenth:{$imagesize}");
readfile('a.txt');
move_uploaded_file(filename, destination)
php.ini
upload_max_filesize = 200M
post_max_size = 80M
php操做mysql數據庫
1.經過php鏈接mysql
2.選擇數據庫
3.insert
4.delete
5.update
6.select
經過php鏈接mysql
mysql_connect('localhost','root','123');
選擇數據庫
mysql_select_db('test');
設置客戶端和鏈接字符集
mysql_query('set names utf8');
經過php進行insert操做
釋放鏈接資源
mysql_close($conn);
從結果集中取數據:
mysql_fetch_assoc 關聯數組
mysql_fetch_row 索引數組
mysql_fetch_array 混合數組
mysql_fetch_object 對象
從結果中取所有數據:
while($row = mysql_fetch_assoc($result)){
echo "<pre>";
print_r($row);
echo "</pre>";
}
mysql_error(); //mysql錯誤信息
mysql_errno(); //mysql錯誤編碼
mysql_insert_id(); //取得上一步insert插入的ID
mysql_affected_rows(); //取得最近一次INSERT,UPDATE 或 DELETE 查詢所影響的記錄行數
mysql_num_rows(); //獲得select操做影響的行數
網站系統
1.目錄結構
前臺 home
後臺 admin
前臺入口文件 index.php
2.需求分析
後臺:
用戶管理
分類管理
品牌管理
商品管理
訂單狀態管理
訂單管理
前臺:
首頁
品牌頁面
商品詳情
商品評論管理
購物車管理
結算頁面
用戶登陸和退出
我的中心管理
訂單提交頁面
3.目錄結構細化
myshop
------------
|--index.php 網站首頁(跳轉到home/index.php前臺首頁)
|
|--public/ 公共資源目錄(先後臺共用的數據庫鏈接文件和函數庫)
| |--common/ 函數庫
| | |--config.inc.php 公共配置文件
| | |--functions.php 函數庫文件
| |--images/ 公共圖片
| |--css/ 公共css
| |--upload/ 公共圖片上傳
| | |--admin/ 後臺圖片上傳
| | |--home/ 前臺圖片上傳
|
|--admin/ 後臺管理目錄
| |--index.php 後臺網站首頁
| |--login/
| | |--login.php 後臺登錄頁
| | |--check.php 登錄驗證頁
| | |--logout.php 後臺退出頁
| |
| |--public/ 公共資源目錄
| | |--css/ 存放後臺css文件目錄
| | |--js/ 存放後臺js文件目錄
| | |--imgs/ 存放後臺圖片目錄
| | |--header.php 頁頭
| | |--menu.php 導航欄頁面
| | |--main.php 後臺首頁
| | |--acl.php 網站後臺權限文件
| |
| |--user/ 用戶管理目錄(普通用戶和管理員共用表)
| | |--index.php 瀏覽信息
| | |--add.php 添加信息
| | |--insert.php 插入信息
| | |--edit.php 編輯信息
| | |--update.php 更改信息
| | |--del.php 刪除信息
| |
| |--shopclass/ 商品分類管理
| | |--index.php 瀏覽信息
| | |--add.php 添加信息
| | |--insert.php 插入信息
| | |--edit.php 編輯信息
| | |--update.php 更改信息
| | |--del.php 刪除信息
| |
| |--brand/ 品牌管理
| | |--index.php 瀏覽信息
| | |--add.php 添加信息
| | |--insert.php 插入信息
| | |--edit.php 編輯信息
| | |--update.php 更改信息
| | |--del.php 刪除信息
| |
| |--shop/ 商品信息管理
| | |--index.php 瀏覽信息
| | |--add.php 添加信息
| | |--insert.php 插入信息
| | |--edit.php 編輯信息
| | |--update.php 更改信息
| | |--del.php 刪除信息
| | |--updown.php 商品上下架頁面
| |
| |--order/ 訂單信息管理
| | |--index.php 瀏覽信息
| | |--status.php 編輯訂單狀態
| | |--update.php 更改訂單狀態
|
|
|--home/ 網站前臺目錄
| |--public/ 公共資源目錄
| | |--css/ 存放前臺css文件目錄
| | |--images/ 存放前臺圖片文件目錄
| | |--header.php 前臺導航頁面
| | |--footer.php 前臺底部頁面
| | |--acl.php 網站前臺權限文件
| |
| |--index.php 前臺首頁
| |
| |--brandlist.php 品牌列表頁(分頁實現,顯示單個品牌下的)
| |
| |--shopinfo.php 商品詳情頁(單個商品的放入購物車頁面,下面有商品評論)
| |
| |--cart/ 購物車管理
| | |--addcart.php 加入購物車
| | |--clearcart.php 清空購物車
| | |--opcart.php 操做購物車(add,rem,del操做)
| |
| |--account.php 結算頁面
| |
| |--ordercommit.php 提交訂單(把購物清單插入到訂單表,讓後臺使用)
| |
| |--center.php 我的中心(用戶信息[密碼,地址,電話,郵箱],查看個人訂單)
| |
| |--user/
| | |--register.php 註冊
| | |--login.php 登錄
| | |--check.php 驗證
| | |--logout.php 退出
| |
4.數據庫設計
-- user表
-- 用戶表
create table if not exists user(
id int unsigned not null auto_increment,
username varchar(50) not null,
password varchar(50) not null,
regtime int not null,
admin tinyint not null,
primary key(id)
);
-- shopclass表
-- 商品分類
create table if not exists shopclass(
id int unsigned not null auto_increment,
name varchar(50) not null,
primary key(id)
);
-- brand表
-- 品牌
create table if not exists brand(
id int unsigned not null auto_increment,
name varchar(50) not null,
shopclass_id int not null,
primary key(id)
);
-- shop表
-- 商品表
create table if not exists shop(
id int unsigned not null auto_increment,
name varchar(50) not null,
price float not null,
stock int not null,
upshelf tinyint not null,
image varchar(100) not null,
brand_id int not null,
primary key(id)
);
-- orderstat表
-- 訂單狀態
create table if not exists orderstat(
id int unsigned not null auto_increment,
name varchar(50) not null,
primary key(id)
);
-- relation表
-- 聯繫方式
create table if not exists relation(
id int unsigned not null auto_increment,
realname varchar(50) not null,
address varchar(200) not null,
telephone varchar(20) not null,
email varchar(50) not null,
user_id int not null,
primary key(id)
);
-- orders表
-- 訂單表
create table if not exists orders(
id int unsigned not null auto_increment,
code varchar(50) not null,
user_id int not null,
shop_id int not null,
num int not null,
price float not null,
time int not null,
orderstat_id int not null,
relation_id int not null,
primary key(id)
);
-- commit表
-- 評論
create table if not exists commit(
id int unsigned not null auto_increment,
content text,
user_id int not null,
shop_id int not null,
primary key(id)
);
5.組合sql語句
6.導入數據庫
7.php程序編寫