PHP operation MySQL database record operation function

Source: Internet
Author: User

Introduction: This is a detailed page for PHP to operate MySQL database recording operation functions. It introduces PHP, related knowledge, skills, experience, and some PHP source code.

Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 325731 'rolling = 'no'>
Database record operation functions (5 ):



1. mysql_fetch_array ()

Format: array mysql_fetch_array (INT query );



If the execution is successful, an array is returned. The array contains the value of the next record. If the execution fails, false is returned.

The returned array can be expressed by subscript or field name.



Example:

<? PHP

$ Query = mysql_query ($ SQL, $ Connect );

While ($ arrary = mysql_fetch_array ($ query ))

{



Echo $ array [column1]. "|". $ array [column2];

// Echo $ array [0]. "|". $ array [1];



}

?>

Note: The subscript of the array starts from 0!



2. mysql_fetch_row ()

Format: array = mysql_fetch_row (INT query );



The function is basically the same as the mysql_fetch_array () function of 1. The difference is that mysql_fetch_row () can only be expressed as an array subscript.

1 array is returned successfully, and false is returned if the operation fails.



Example:

<? PHP

$ Query = mysql_query ($ SQL, $ Connect );

While ($ ROW = mysql_fetch_row ($ query ))

{

Echo $ row [0]. "|". $ row [1]. "<br> ";

}

?>

Note: The mysql_fetch_row () function can only be represented by an array subscript and start from 0.

In addition, mysql_fetch_row () is faster than mysql_fetch_array () and reads data from the next row.



3. mysql_result ()

Format: int mysql_result (INT query, int row, string filedname );



In mysql_result (), the row parameter must start from 0, and the filedname parameter must be a real field name, which cannot be expressed by subscript.

If the execution is successful, the value of the Field Retrieved from the database is returned. If the execution fails, the value of false is returned.



Example:

<? PHP

$ Query = mysql_query ($ SQL, $ Connect );

Echo mysql_result ($ query, 0, "column1"). "<br> ";

Echo mysql_result ($ query, 1, "column1"). "<br> ";

Echo mysql_result ($ query, 2, "column1"). "<br> ";

?>



Note: This function has few functions but is easy to use.



4. mysql_fetch_object ()

Format: Object mysql_fetch_object (INT query)



The specified field can be read cyclically. If the execution is successful, a value is returned in the form of an object. If the operation fails, a value of false is returned.



Example:

<? PHP

$ Query = mysql_query ($ SQL, $ Connect );

While ($ object = mysql_fetch_object ($ query ))

{

Echo $ object-> column1. "<br> ";

Echo $ object-> column2. "<br> ";

Echo $ object-> column3. "<br> ";

}

?>





Note: After the mysql_fetch_object () function is successfully executed, one object is returned!

The procedure is as follows:

$ Object-> Field name



5. mysql_data_seek ()

Format: int mysql_data_seek (INT row, int query );

Move the cursor to the specified row (row_number)

If the execution is successful, true value is returned. If the execution fails, false is returned.

This function can be used with mysql_fetch_array () or mysql_fetch_row (). After using the mysql_data_seek () function, you can use mysql_fetch_array () or mysql_fetch_row () function to display the specified row.



Example:

<? PHP

$ Query = mysql_query ($ SQL, $ Connect );

$ Seek = mysql_data_seek ($ query, 2 );

$ Arrary = mysql_fetch_array ($ query );

Echo $ array [column1]. "<br> ";

Echo $ array [column2]. "<br> ";

?>

Database record operation functions (5 ):



1. mysql_fetch_array ()

Format: array mysql_fetch_array (INT query );



If the execution is successful, an array is returned. The array contains the value of the next record. If the execution fails, false is returned.

The returned array can be expressed by subscript or field name.



Example:

<? PHP

$ Query = mysql_query ($ SQL, $ Connect );

While ($ arrary = mysql_fetch_array ($ query ))

{



Echo $ array [column1]. "|". $ array [column2];

// Echo $ array [0]. "|". $ array [1];



}

?>

Note: The subscript of the array starts from 0!



2. mysql_fetch_row ()

Format: array = mysql_fetch_row (INT query );



The function is basically the same as the mysql_fetch_array () function of 1. The difference is that mysql_fetch_row () can only be expressed as an array subscript.

1 array is returned successfully, and false is returned if the operation fails.



Example:

<? PHP

$ Query = mysql_query ($ SQL, $ Connect );

While ($ ROW = mysql_fetch_row ($ query ))

{

Echo $ row [0]. "|". $ row [1]. "<br> ";

}

?>

Note: The mysql_fetch_row () function can only be represented by an array subscript and start from 0.

In addition, mysql_fetch_row () is faster than mysql_fetch_array () and reads data from the next row.



3. mysql_result ()

Format: int mysql_result (INT query, int row, string filedname );



In mysql_result (), the row parameter must start from 0, and the filedname parameter must be a real field name, which cannot be expressed by subscript.

If the execution is successful, the value of the Field Retrieved from the database is returned. If the execution fails, the value of false is returned.



Example:

<? PHP

$ Query = mysql_query ($ SQL, $ Connect );

Echo mysql_result ($ query, 0, "column1"). "<br> ";

Echo mysql_result ($ query, 1, "column1"). "<br> ";

Echo mysql_result ($ query, 2, "column1"). "<br> ";

?>



Note: This function has few functions but is easy to use.



4. mysql_fetch_object ()

Format: Object mysql_fetch_object (INT query)



The specified field can be read cyclically. If the execution is successful, a value is returned in the form of an object. If the operation fails, a value of false is returned.



Example:

<? PHP

$ Query = mysql_query ($ SQL, $ Connect );

While ($ object = mysql_fetch_object ($ query ))

{

Echo $ object-> column1. "<br> ";

Echo $ object-> column2. "<br> ";

Echo $ object-> column3. "<br> ";

}

?>





Note: After the mysql_fetch_object () function is successfully executed, one object is returned!

The procedure is as follows:

$ Object-> Field name



5. mysql_data_seek ()

Format: int mysql_data_seek (INT row, int query );

Move the cursor to the specified row (row_number)

If the execution is successful, true value is returned. If the execution fails, false is returned.

This function can be used with mysql_fetch_array () or mysql_fetch_row (). After using the mysql_data_seek () function, you can use mysql_fetch_array () or mysql_fetch_row () function to display the specified row.



Example:

<? PHP

$ Query = mysql_query ($ SQL, $ Connect );

$ Seek = mysql_data_seek ($ query, 2 );

$ Arrary = mysql_fetch_array ($ query );

Echo $ array [column1]. "<br> ";

Echo $ array [column2]. "<br> ";

?>

More articles on "using PHP to operate MySQL database record operation functions"

Love J2EE follow Java Michael Jackson video station JSON online tools

Http://biancheng.dnbcw.info/php/325731.html pageno: 13.

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.