PHP and database links

Source: Internet
Author: User
PHP and database links I checked the DISCUZ database tool class
I have a question:
Function dql ($ SQL)
{
$ Res = $ this-> mysqli-> query ($ SQL );
If (! Empty ($ res ))
{
$ Arr = array ();
While ($ row = $ res-> fetch_row ())
{$ Arr [] = $ row ;}
Return $ arr;
$ Res-> free_result ();
} Else
{Return null ;}
It turns the data obtained from the database into an array $ ROW and stores $ row to $ arr. then, it returns a two-dimensional array.
Why not a $ row is returned directly? Why two more packages?


Reply to discussion (solution)

Returns a $ row. how do you get all records.

If only $ row is returned, only the last row is obtained.
A two-dimensional array is returned, and multiple data entries in the table structure are returned.

$ Row is a record. if it is not encapsulated into a two-dimensional array, you will always get a record, even if you loop it into a record (the last record in the table ).
To obtain more records, we need to put the one-dimensional array into the two-dimensional array so that the previous data will not be overwritten during the loop so that the data will be taken out.

$ Row every time? Take one ???, So we need to follow? Go? .

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.