Avoid waste of database resources

Source: Internet
Author: User

Skillfully used: mysql_num_rows--get the number of rows in the result set;--for Select Lookup$query =mysql_query (SELECT * FROM table_name); if ($query && mysql_num_rows ($query))//Perform data output only when there is data in the database{while ($row = Mysql_fetch_row ($query)) {echo $row.    <br> "; }}else{echo "No data!" ";}//If you change to if ($query) the query succeeds even if no data is still outputSkillfully used: mysql_affected_rows ([Resource $link _identifier])--A parameter "database resource" obtainedlast timeAssociated with the Link_identifierinsert,update or DELETEThe number of record rows affected by the query.This function is removed after PHP5.5.0, it is recommended to use: Mysqli_affected_rows () or Pdostatement::rowcount ()$query = mysql_query ("UPDATE table_name set name= ' LMS ' where ID <); if ($query && mysql_affected_rows ($con))//The output succeeds only if the updated data succeeds successfully-when the updated data is consistent with the original data, the affected data is 0 and is not updated{echo ' modified successfully! ‘;} else{Echo ' modification failed ';}

Avoid waste of database resources

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.