最近2018中文字幕在日韩欧美国产成人片_国产日韩精品一区二区在线_在线观看成年美女黄网色视频_国产精品一区三区五区_国产精彩刺激乱对白_看黄色黄大色黄片免费_人人超碰自拍cao_国产高清av在线_亚洲精品电影av_日韩美女尤物视频网站

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
php數(shù)據(jù)庫json PHP數(shù)據(jù)庫連接失敗的原因及解決方法

PHP接收json 并將接收數(shù)據(jù)插入數(shù)據(jù)庫的實現(xiàn)代碼

最近有一個需求,前端向后臺提交json,后臺解析并且將提交的值插入數(shù)據(jù)庫中,

成都網(wǎng)絡(luò)公司-成都網(wǎng)站建設(shè)公司成都創(chuàng)新互聯(lián)10余年經(jīng)驗成就非凡,專業(yè)從事做網(wǎng)站、成都做網(wǎng)站,成都網(wǎng)頁設(shè)計,成都網(wǎng)頁制作,軟文發(fā)稿,廣告投放等。10余年來已成功提供全面的成都網(wǎng)站建設(shè)方案,打造行業(yè)特色的成都網(wǎng)站建設(shè)案例,建站熱線:028-86922220,我們期待您的來電!

難點

1、php解析json(這個不算難點了,網(wǎng)上實例一抓一大把)

2、解析json后,php怎樣拿到該拿的值

?php

require

('connect.php');

/*

本例用到的數(shù)據(jù):

post_array={"order_id":"0022015112305010013","buyer_id":"2","seller_id":"1","all_price":"100.00","json_list":[{"product_id":"3","product_number":"3"},{"product_id":"8","product_number":"2"},{"product_id":"10","product_number":"4"}]}

*/

$post_array=$_POST['post_array'];

//--解析Json,獲取對應(yīng)的變量值

$obj=json_decode($post_array,TRUE);

$order_id

=

$obj['order_id'];

$buyer_id

=

$obj['buyer_id'];

$seller_id

=

$obj['seller_id'];

$all_price

=

$obj['all_price'];

$i=0;//循環(huán)變量

//--得到Json_list數(shù)組長度

$num=count($obj["json_list"]);

//--遍歷數(shù)組,將對應(yīng)信息添加入數(shù)據(jù)庫

for

($i;$i$num;$i++)

{

$list_product_id[]=$obj["json_list"][$i]["product_id"];

$list_product_number[]=$obj["json_list"][$i]["product_number"];

$insert_order_product_sql="INSERT

INTO

tbl_order_product

(order_id,product_id,product_number)

VALUES

(?,?,?)";

$result

=

$sqlconn

-

prepare($insert_order_product_sql);

$result

-

bind_param("sss",

$order_id,$list_product_id[$i],$list_product_number[$i]);

$result-execute();

}

//--添加訂單信息

$insert_order_sql="INSERT

INTO

tbl_order

(order_id,buyer_id,seller_id,all_price)

VALUES

(?,?,?,?)";

$result=$sqlconn-prepare($insert_order_sql);

$result-bind_param("ssss",$order_id,$buyer_id,$seller_id,$all_price);

$result-execute();

$result

-

close();

$sqlconn

-

close();

?

投稿者信息

昵稱:

Hola

Email:

[email protected]

php查詢數(shù)據(jù)庫數(shù)據(jù)并json顯示

header("Content-type:text/html;charset=utf-8");

mysql_connect('主機名','賬號','密碼');

mysql_select_db('數(shù)據(jù)庫名');

mysql_query('set?names?utf8');

$sql="SELECT?username,regdate?FROM?表名?where?username='".$_GET['USERNAME']."'";

$res=mysql_query($sql);

if($row?=?mysql_fetch_row($res)){

$json?=?array(

'state'=true,

'username'=$row[0],

'regdate'=$row[1],

'rand_num'=date('Y/m/d?H:i:s')

);

}else{

$json?=?array(

'state'=false,

'rand_num'=date('Y/m/d?H:i:s')

);

}

echo?json_encode($json);

exit();

明白的人應(yīng)該一眼就能看懂吧

json數(shù)據(jù)怎么通過php存入數(shù)據(jù)庫

返回的就是json字符串,可以直接存入PHP

mysql_query("insert into table(info) values('".$info."')");


本文標(biāo)題:php數(shù)據(jù)庫json PHP數(shù)據(jù)庫連接失敗的原因及解決方法
鏈接URL:http://fisionsoft.com.cn/article/dojojhi.html