PHP link MySQL Database

Source: Internet
Author: User

First step: Link the database

    • Mysqli_connect ();
      • Parameter 1: Address of the linked database
      • Parameter 2: User name of the database
      • Parameter 3: the database Mask
      • Parameter 4: Optional parameter, default database to be manipulated
      • Return value: Successfully returned object, failed return false

Step two: Select the database

    • mysqli_select_db ();
      • Parameter 1: Object identity returned successfully by the Mysqli_connect () Link database.
      • Parameter 2: The database to be manipulated or to be changed
      • Return value: Select database successfully returns TRUE, Failure returns false

Step three: Set character sets

    • Mysqli_set_charset ();
      • Parameter 1: Object identity returned successfully by the Mysqli_connect () Link database.
      • Parameter 2: The character set to be set, utf-8 in the database to UTF8
      • Return value: Success is true, failure is false

Fourth step: Prepare the SQL statement to be manipulated

    • Prepare to increase \ delete \ change \ Check

Fifth step: Send SQL statements

    • Mysqli_query ();
      • Parameter 1: The object ID that was successfully returned by the Mysqli_connect () Link database.
      • Parameter 2: SQL statement to send
      • return value:
      • When added, deleted, modified, successfully returns TRUE, Failure returns false
      • When the query is made, the successful return of an object fails to return False

Sixth step: Judging and processing the results

    • Mysqli_affected_rows () returns the affected line of the previous MySQL operation
      • Parameter 1: The object ID that was successfully returned by the Mysqli_connect () Link database.
      • Return value: Returns the affected row if there is an impact row, or returns 1 if no 0 is returned
      • Note: In the increase, deletion, change will affect the line generated
    • Mysqli_num_rows () returns the number of rows in the query data
      • Parameter 1: An object with Mysqli_query () executing the query statement successfully returned,
      • Return value: Returns the number of rows queried to the data in this object
      • Note: The number of rows queried to the data is returned when a query operation is made
    • MYSQLI_FETCH_ASSOC () Gets a row from the query success result object returned as an associative array
      • Parameter 1: Object successfully returned by Mysqli_query () execution of query statement
      • Return value: Returns a row of data from a modified object as an associative array

Seventh step: Close the database

    • Mysqli_close ()
      • Parameter 1: Object identity returned successfully by the Mysqli_connect () Link database.
      • Return value: Successful return True, failed return Fasle
    • MYSQLI_INSERT_ID () returns the unique ID generated by the previous step of the add operation
      • Parameter: The object identity that was successfully returned by the Mysqli_connect () Link database.
      • Return value: Returns the ID of the currently inserted data.

PHP link MySQL Database

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.