Some functions of PHP getting data from MySQL

Source: Internet
Author: User

  1. 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
  2. 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
  3. 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);
  4. 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 ';}

  5. The
  6. 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  
  7. 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

Related Article

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.