PHP database Operations common commands, PHP database common commands _php tutorial

Source: Internet
Author: User
Tags php database

PHP database Operations common commands, PHP database common commands


 Php//Set character setsHeader("Content-type:text/html;charset=utf8");//connect to the database and determine success or not$link=mysql_connect(' localhost ', ' root ', ' root ') or die(' Connection failed ');//Select Databasemysql_select_db(' Database name ');//Set character setsMysql_set_charset (' UTF8 ');//Preparing SQL statements$sql= "SELECT * from User";//Send SQL statement$result=mysql_query($sql);//determine if the SQL statement executed was successfulif($result&&mysql_affected_rows() >0){    Echo' Query succeeded ';}Else{    Echo' Query failed ';}//To close a database connectionMysql_close();//PHP Database Operations common Commandsrequire,include//use a function to include a file inmysql_connect(' localhost ', ' root ', ' root ')//connecting to a databasemysql_select_db(' Database name ')//Select DatabaseMysql_set_charset (' UTF8 ')//Set character setsMysql_errno()//Error NumberMysql_error()//error Messagemysql_query(' SQL statement ')//Execute SQL statement successfully returns a resource, failure returns falseMysql_free_result($result)//Freeing ResourcesMysql_close()//Close the databasemysql_affected_rows($link)//returns the number of rows affected the general addition of modified Delete when the judgmentmysql_insert_id($link)//If the table has a self-increment ID added successfully, the self-increment ID will be returned through this functionmysql_num_rows($result)//only for queries returning the number of records in the result setMysql_fetch_array($result)//returns a mixed array of records in the result set as an array understandMysql_fetch_row($result)//return the records in the result set as an array to an indexed array.Mysql_fetch_assoc($result)//returning the records in the result set as an array the associated array is recommended and mastered

http://www.bkjia.com/PHPjc/1082220.html www.bkjia.com true http://www.bkjia.com/PHPjc/1082220.html techarticle PHP Database operations commonly used commands, PHP database common commands? PHP//Set the character Set header ("Content-type:text/html;charset=utf8");//Connect the database and determine whether it is successful $link =...

  • 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.