PHP mysqli Operations Database

Source: Internet
Author: User

Start

Due to the abolition of the MySQL connection mode, it is said that the use of mysql_connect () in PHP7 requires additional download components.
There are process-oriented and object-oriented two ways of using mysqli.
The MYSQLI provides three classes:

  • MYSQLI Connections related to

  • Mysqli_result Processing Result Sets

  • MYSQLI_STMT Preprocessing class

  • Database connection

     
      Set_charset ("UTF8");//or $mysqli->query ("Set names ' UTF8 '")//Close connection $mysqli->clise ()//process-oriented mode of connection $mysqli = Mysqli_connect ($db _host, $db _user, $db _pwd, $db _name);//Determine if the connection is successful if (! $mysqli) {    echo mysqli_connect_error ();} Close connection Mysqli_close ($MYSQLI);? >

    Database queries

    Common: Execute SQL statements are available in query (SQL), execution failure returns False,select success returns the result set object, and other returns true, as long as it is not false to indicate that the SQL statement executed successfully.

     
      Query ($sql);//or $sql = "DELETE from table_name where name= ' xiaoming '"; $result = $mysqli->query ($sql); if ($result = = = = False) {    echo $mysqli->error;    echo $mysqli->errno;} affect the number of lines echo $mysqli->num_rows;//inserted idecho $mysqli->insert_id; $mysqli->close ();

    Have result set

     
      Query ($sql), if ($result = = = False) {//execution failed    echo $mysqli->error;    echo $mysqli->errno;} Number of rows echo $result->num_rows;//column number fields echo $result->field_count;//get field information $field_info_arr = $result->fetch_ Fields ();//move record pointer//$result->data_seek (1);//0 reset Pointer to start//Fetch data while ($row = $result->fetch_assoc ()) {    echo $ row[' name '];    echo $row [' Address '];} You can also get all the data at once//$result->data_seek (0), or//If you have moved the pointer before you need to reset $data = $result->fetch_all (MYSQLI_ASSOC); $mysqli Close ();
  • 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.