10个PHP数据库操作函数,使数据库管理更加简单
1. mysqli_connect()
This function establishes a connection to the MySQL server and returns a mysqli object. It requires the server name, username, password, and database name as parameters.
2. mysqli_query()
This function sends a query or command to the MySQL server and returns a result set as a mysqli_result object. It requires the mysqli object returned by mysqli_connect() and a SQL statement as parameters.
3. mysqli_fetch_assoc()
This function retrieves a row of data from the result set returned by mysqli_query() as an associative array where the keys are the column names and the values are the column values. It requires the mysqli_result object returned by mysqli_query() as a parameter.
4. mysqli_num_rows()
This function returns the number of rows in the result set returned by mysqli_query(). It requires the mysqli_result object returned by mysqli_query() as a parameter.
5. mysqli_insert_id()
This function returns the auto-generated ID generated by an INSERT command. It requires the mysqli object returned by mysqli_connect() as a parameter.
6. mysqli_real_escape_string()
This function escapes any special characters in a string to prevent SQL injection attacks. It requires the mysqli object returned by mysqli_connect() and a string as parameters.
7. mysqli_error()
This function returns the error message generated by the MySQL server. It requires the mysqli object returned by mysqli_connect() as a parameter.
8. mysqli_fetch_array()
This function retrieves a row of data from the result set returned by mysqli_query() as both an associative array and a numeric array. It requires the mysqli_result object returned by mysqli_query() as a parameter.
9. mysqli_affected_rows()
This function returns the number of rows affected by an UPDATE, DELETE, or INSERT command. It requires the mysqli object returned by mysqli_connect() as a parameter.
10. mysqli_close()
This function closes the connection to the MySQL server. It requires the mysqli object returned by mysqli_connect() as a parameter.
