Home >Backend Development >PHP7 >What are the native MySQL database operations in PHP7?
In PHP, we often use the mysql database, but do you know what are the native MySQL database operations of PHP7? Today, the editor will take you through it, and you can refer to it if you need it.
mysqli_connect(host, username, password [,dbname] [,port]);
- Parameters :
host: MySQL server. Can contain port number, the default value is "localhost:3306"
username: username. The default value is the username of the server process owner;
password: password.
dbname: database name.
port: The port number of the MySQL server, the default is 3306.
- Return value: If the connection is successful, the mysqli connection object is returned. If failed, returns false.
mysqli_select_db(mysqliLink, database)
- Description: A database server may contain many databases, and usually requires programming for a specific database
- Return value: TRUE if successful, FALSE if failed
mysqli_set_charset(mysqliLink, charset)
- Description: Set the default character encoding
- Returns: TRUE on success, or FALSE on failure.
mysqli_query(mysqliLink, queryStr)
- Parameters:
query is the query string;
link Is an active database connection created;
- Description: mysqli_query() only returns a mysqli_result result set object for SELECT, SHOW or DESCRIBE statements. If the query is executed incorrectly, it returns FALSE. For other types of SQL statements, mysqli_query() returns TRUE when executed successfully and FALSE when an error occurs. A return value other than FALSE means that the query is valid and can be executed by the server.
- Note: The query string should not end with a semicolon, which is different from the command line mode.
mysqli_fetch_array (mysqliResult [, resultType])
- Parameters: resultType is a Constant, value: MYSQLI_BOTH (both, default), MYSQLI_ASSOC (associative index), MYSQLI_NUM (numeric index)
- Return: Returns an array generated based on the rows obtained from the result set, if there are no more rows Return FALSE.
- Note: The field names returned by this function are case-sensitive.
mysqli_fetch_all(mysqliResult [, resultType ])
- Parameters: $result_type Is a constant with values: MYSQLI_BOTH (both, default), MYSQLI_ASSOC (associative index), MYSQLI_NUM (numeric index)
- Return: Returns an array generated based on the rows obtained from the result set, if Returns FALSE if there are no more rows.
- Note: The field names returned by this function are case-sensitive.
mysqli_num_rows(mysqliResult)
- Note: This command is only valid for SELECT statements.
array mysqli_fetch_assoc(mysqliResult)
- Return value: an associative array generated from the rows obtained from the result set, if there are no more line returns FALSE;
- Note: The field names returned by this function are case-sensitive.
mysqli_affected_rows (mysqliLink)
- Description: Get the latest SELECT, INSERT, UPDATE or The number of rows affected by the DELETE query.
- Note: If the latest query fails, the function returns -1. When using UPDATE query, MySQL will not update the original value and the new value. The return value is not necessarily the record that meets the query conditions. Only the number of modified records will be returned.
mysqli_free_result(mysqliResult)
- Parameters: mysqliResult is the result set object.
mysqli_connect_error()
- Parameters: No parameters
Recommended learning:php video Tutorial
The above is the detailed content of What are the native MySQL database operations in PHP7?. For more information, please follow other related articles on the PHP Chinese website!