- Returns a single piece of data as a one-dimensional indexed array: mysql_fetch_row
Call format: $row = mysql_fetch_row ($query)
Function: Returns a single piece of data in the result set
Parameter: mysql_query The resource identifier returned
Return value: A one-dimensional indexed array$query mysql_query // mysql_query When executing the SELECT command, returns the resource identifier if successful while ($rowmysql_fetch_row($query)) { echo$row[0]. $row[1]. ' A <br/> ';} // Mysql_fetch_row takes one piece of data from the resource, the result set, and returns it as an array each time it is executed, until the last data is taken to return an empty result
- Returns one data in one-dimensional associative array: MYSQL_FETCH_ASSOC call format: $row = MYSQL_FETCH_ASSOC ($query) function: Returns a data parameter in the result set as an associative array: mysql_ Query returns the resource identifier return value: a one-dimensional associative array
- Get data in mixed array form: mysql_fetch_array
Call format: $row = mysql_fetch_array ($query [, $op])
Function: Returns a single piece of data in an indexed array or/and associative array form
Parameter: mysql_query The resource identifier returned, [return selection, can]
Return value: 1, MYSQL_ASSOC-associative array
2, Mysql_num-numeric array (indexed array)
3, Mysql_both-default, associative array + indexed array/************* associative array ***************/Mysql_fetch_array($query,MYSQL_ASSOC);Mysql_fetch_assoc($query);/************* indexed Array ***************/Mysql_fetch_row($query);Mysql_fetch_array($query,mysql_num);/************* associative + indexed array *********/Mysql_fetch_array($query,mysql_both);Mysql_fetch_array($query);
- Get the number of rows in the result set: mysql_num_rows call Format: mysql_num_rows ($query) function: Returns the number of rows in the result set parameter: mysql_query returns the resource identifier return value: Number of rows, return 0 when the result set is empty
$query mysql_query (' SELECT * from Fruitshop '); if ($querymysql_num_rows($query)) { // output of data while ($rowmysql_fetch_row($query)) { }} Else { echo ' no data ';}
- The
- gets the value of a field in the result set: mysql_result call Format: $val = mysql_result ($query, $row, $iterm) function: Returns the value parameter of the specified field in the result set: Resource identifier, line number starting at 0, Return value from 0-based offset: Specifies the value of the field
echo mysql_result ( $query , 2, 1); // Returns the third row, the second value
- Gets the number of record rows affected by the previous operation: Mysql_affected_rows call format: $val = Mysql_affected_rows ($link) Action: Gets the number of record rows affected by the last operation parameter: Mysql_ The connection resource identifier returned by connect returns a value: The number of rows affected by the previous operation, and the same 0 for the modified data and the original data
if (mysql_query(' Update fruitshop set num=9 where Id=1 ')} { echo "modified successfully, the number of data bars modified is"; echomysql_affected_rows($con); // The connection identifier, which affects the number of bars 0} when the modified datais the same as before Else { echo "modification failed";}
Reference: http://www.imooc.com/learn/116
Some functions of PHP getting data from MySQL