How about high three nights?-JSON & amp; PHP, _ PHP Tutorial

Source: Internet
Author: User
How about high three nights?-JSON & amp; PHP ,. Hi, I went to eat hot pot last night. right, you didn't guess it was wrong. I just had a treat from my senior brother in Chengdu tonight. tomorrow I have a hot pot for friends, should I have been busy for three nights?-JSON & PHP,

Hi

I went to eat hot pot last night. Yes, you didn't guess it was wrong. I was in Chengdu.

There will be a treat for senior students tonight, and there will be a hot pot for friends tomorrow. Should the busy week have to be high for three consecutive nights (single graduate dogs are so easy to satisfy ). So I had to leave my business to write and write (not to write ...)

1. JSON

----- Introduction -----

Javascript Object Notation, a lightweight data exchange format

---

Basic syntax: Four Basic rules

The parallel data are separated by commas; the ING is represented by colons; the parallel data set (array) is represented by []; the ing set (object) is represented {}

For example, Beijing has an area of 16800 square kilometers and a resident population of 16 million people. Shanghai has an area of 6400 square kilometers and a resident population of 18 million people.

In JSON format:

[

{"City": "Beijing", "area": 16800, "population": 1600 },

{"City": "Shanghai", "area": 6400, "population": 1800}

]

---

Advantages: simple format, easy to read/write and transmit; support for multiple languages

Disadvantage: the character set must be Unicode; the syntax is too rigorous

2. PHP & MySQL

----- Php built-in mysql function (2 )-----

---- Four fetch functions _ fetch results

---

$ Query = mysqli_query ($ con, 'select * from test ');

Print_r (mysqli_fetch_row ($ query ));

The first fetch, mysql_fetch_row (), returns only the data of the first row;Note: In fact, it reads a row every time, row by row, So we can all come out like this:

$ Query = mysqli_query ($ con, 'select * from test ');
While ($ row = mysqli_fetch_row ($ query )){
Print_r ($ row );
}

In addition, if the number of calls exceeds the number of rows, no data exceeding the number of rows will be output, and null will be returned.

Array ([0] => 1 [1] => Tom) Array ([0] => 2 [1] => Tom) array ([0] => 3 [1] => Tom) Array ([0] => 4 [1] => Tom) array ([0] => 5 [1] => ???? ) Array ([0] => 6 [1] => Tom) Array ([0] => 7 [1] => ???? )

The returned result is an index array.

---

Mysql_fetch_array ()

$ Arr = mysqli_fetch_array ($ query );
Print_r ($ arr );

The usage is similar. result:

Array ([0] => 1 [id] => 1 [1] => Tom [name] => Tom)

Compare database data

Mysql> SELECT * from test;
+ ---- + ------ +
| Id | name |
+ ---- + ------ +
| 1 | Tom |
| 2 | Tom |
| 3 | Tom |
| 4 | Tom |
| 5 | ???? |
| 6 | Tom |
| 7 | ???? |
+ ---- + ------ +

Therefore, row generates an index array from a data record. by default, array retrieves a data record to generate an index array and an associated array.

Simply put, array can use the key name, which is quite convenient:

Echo $ arr ['name'];

However, the speed of array is a little slower.

At the same time, array also has the optional second parameter, which can be selected to output some arrays.

$ Arr = mysqli_fetch_array ($ query, MYSQL_ASSOC );
Print_r ($ arr );
Echo $ arr ['name'];

Get

Array ([id] => 1 [name] => Tom) Tom

MYSQL_ASSOC, MYSQL_NUM, and MYSQL_BOTH are three parameters.

---

Mysql_fetch_assoc ()

Basically, the output is the same as that in the previous section.

---

Mysql_fetch_object ()

An object is returned.

$ Obj = mysqli_fetch_object ($ query );
Echo $ obj-> name;

Echo"
";

Print_r ($ obj );

Result

Tom
StdClass Object ([id] => 1 [name] => Tom)

Similar to the row command, the output of a row can also be

Hi, I went to eat hot pot last night. Yes, you didn't guess it was wrong. I just had a treat from my senior brother in Chengdu tonight. I 'd like to have a hot pot tomorrow with friends...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.