Home >Backend Development >PHP Tutorial >mysql - Is it json or array? How to insert batches into the database in PHP?
As shown in the picture, is it json or array?
print_r (json_decode($json2)); echo "
"; <br>print_r (json_decode($json2, true)); echo "<pre class="brush:php;toolbar:false">";</p> <p>print_r (json_ecode($json2, true));echo "<pre class="brush:php;toolbar:false">";</p> <p>If it doesn’t work, just use echo to output</p> <p>$pageContents = $client->getContent();//getError<br>$pageContents =str_replace('trde_fullo_get_rsponse','',$pageContents);<br>$pageContents =str_replace('"jdp_rese":"{"":{ "tde":{','',$pageContents);</p> <p>echo $pageContents;</p> <pre class="brush:php;toolbar:false"><code>tid":2356471828086946,"buyer_nick":"图图爱跳舞","created":"2016-09-16 11:24:05","payment":"657.97","pay_time":"2016-09-16 11:24:22","modified":"2016-10-08 21:03:55","num":1,"price":"1985.00","receiver_name":"小百度","receiver_address":" 十里铺先行大厦(务必联系周冰签收!)","status":"TRADE_FINISHED","total_fee":"2054.97","num":1,"oid":2356471828086946,"outer_iid":"gncfastact240x2","payment":"657.97","status":"TRADE_FINISHED","title":"GN美国原装口香糖","price":"1985.00"</code>
Please give me some advice on inserting mysql statements in batches. It would be best if I came with an example. Thank you so much. Newbies are on their way.
As shown in the picture, is it json or array?
print_r (json_decode($json2)); echo "
"; <br>print_r (json_decode($json2, true)); echo "<pre class="brush:php;toolbar:false">";</p> <p>print_r (json_ecode($json2, true));echo "<pre class="brush:php;toolbar:false">";</p> <p>If it doesn’t work, just use echo to output</p> <p>$pageContents = $client->getContent();//getError<br>$pageContents =str_replace('trde_fullo_get_rsponse','',$pageContents);<br>$pageContents =str_replace('"jdp_rese":"{"":{ "tde":{','',$pageContents);</p> <p>echo $pageContents;</p> <pre class="brush:php;toolbar:false"><code>tid":2356471828086946,"buyer_nick":"图图爱跳舞","created":"2016-09-16 11:24:05","payment":"657.97","pay_time":"2016-09-16 11:24:22","modified":"2016-10-08 21:03:55","num":1,"price":"1985.00","receiver_name":"小百度","receiver_address":" 十里铺先行大厦(务必联系周冰签收!)","status":"TRADE_FINISHED","total_fee":"2054.97","num":1,"oid":2356471828086946,"outer_iid":"gncfastact240x2","payment":"657.97","status":"TRADE_FINISHED","title":"GN美国原装口香糖","price":"1985.00"</code>
Please give me some advice on inserting mysql statements in batches. It would be best if I came with an example. Thank you so much. Newbies are on their way.
This is obviously json
<code>// TP3.2批量添加数据 $dataList[] = array('name'=>'thinkphp','email'=>'thinkphp@gamil.com'); $dataList[] = array('name'=>'onethink','email'=>'onethink@gamil.com'); $User->addAll($dataList);</code>
If you want to know whether it is json or an array, you can use var_dump to print it and you will know.
In addition, this is passed from the front end. I visually checked that the json was stringified when passing it. If you want to convert the array in PHP, you still need to Decode a string
<code>json.decode("string...")</code>
As for inserting sql statements in batches, I’ll give you a simple tip, the rest is up to you
<code> INSERT INTO table (q,w,e) VALUES (1,2,3), (2,3,4), (3,4,5), (3,4,9);</code>