一:編寫mysql數(shù)據(jù)庫 開啟服務(wù)器(XAMPP)
1.下載XAMPP,開啟服務(wù)器
2.創(chuàng)建json.sql
/*數(shù)據(jù)庫名:jd;數(shù)據(jù)表名:product*/
/*編碼*/
SET NAMES UTF8;
/*創(chuàng)建jd數(shù)據(jù)庫 設(shè)置編碼utf8*/
CREATE DATABASE jd CHARSET=UTF8;
/*進(jìn)入jd*/
USE jd;
/*創(chuàng)建product數(shù)據(jù)表*/
CREATE TABLE product(
pid INT PRIMARY KEY,
tit VARCHAR(128),
price FLOAT(6,2),
pic VARCHAR(32)
);
/*插入數(shù)據(jù)*/
INSERT INTO product_list VALUES
(1,'小米 Note 全網(wǎng)通 白色 移動聯(lián)通電信4G手機(jī) 雙卡雙待',1199.00,'../images/phone/phone_01.jpg');
/*查詢數(shù)據(jù)表*/
SELECT * FROM product;
3.點擊admin開啟服務(wù)器將sql中的數(shù)據(jù)復(fù)制到服務(wù)器中宾添,完成時點擊右下角執(zhí)行
php增刪改查(增)
1.創(chuàng)建add.php
<?php
$tit=$_REQUEST['tit'];
$price=$_REQUEST['price'];
$pic=$_REQUEST['pic'];
$conn=mysqli_connect('127.0.0.1','root','','jd',3306);
$sql="SET NAMES UTF8";
mysqli_query($conn,$sql);
$sql="INSERT INTO product VALUES(NULL,'$tit','$price','$pic')";
$result=mysqli_query($conn,$sql);
php增刪改查(刪)
1.創(chuàng)建delect.php
<?php
$price=$_REQUEST['price'];
$conn=mysqli_connect('127.0.0.1','root','','jd',3306);
$sql="SET NAMES UTF8";
mysqli_query($conn,$sql);
$sql = "delete from product where price='".$price."'";
$result=mysqli_query($conn,$sql);
php增刪改查(改)
php增刪改查(查)
1.創(chuàng)建delect.php
<?php
header('Content-Type:application/json');
$conn=mysqli_connect('127.0.0.1','root','','message',3306);
$sql="SET NAMES UTF8";
mysqli_query($conn,$sql);
$sql="SELECT * FROM liuyan";
$result=mysqli_query($conn,$sql);