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 ();