Php-mysql result set function comparison

Source: Internet
Author: User

This section focuses on the 4 functions that get a query result set, which are compared in a comprehensive comparison.
Mysql_result (): The advantage is ease of use, and the disadvantage is that the function is small, one call can only get a row of records in the result data set, the larger database is less efficient. Mysql_result ($result, line number, column number) line number and column number are counted starting from 0

Mysql_fetch_row (): The advantage is that the efficiency of execution is the highest in 4 methods; The disadvantage is that you can only use numbers as attribute indexes to get property values, which is very confusing when used.

MYSQL_FETCH_ASSOC (): The property value can only be obtained key=>value form with the property name.

Mysql_fetch_array (): The execution efficiency is also very high, similar to Mysql_fetch_row (), and can be directly obtained by the attribute Name property values, so in practical applications, is the equivalent of Mysql_num_row () and MySQL The combination of _FETCH_ASSOC ().

Mysql_fetch_object (): The use of object-oriented thinking, in the design of ideas more advanced, if the reader is accustomed to object-oriented thinking to write programs, it will be natural to choose it. Second, the advantages of this method are also reflected in the more complex structure of the data results, logic is more clear.

The common denominator of the next 4 functions is to get the data for the current row and then automatically slide back one line. Sometimes, you want to control the number of rows to slide, which is often used with a function that is Mysql_data_seek (), which is defined as:
int mysql_data_seek (int result_identifier,int row_number)
Call this function to slide the row_number row backwards in the result set, and the next time the mysql_fetch_* function is called, the record after the Row_number row is read backwards.

Php-mysql result set function comparison

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.