Home >Backend Development >PHP7 >What are the native MySQL database operations in PHP7?

What are the native MySQL database operations in PHP7?

醉折花枝作酒筹
醉折花枝作酒筹forward
2021-07-19 13:40:293048browse

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.

What are the native MySQL database operations in PHP7?

Connect to the MySQL server

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.

Select the current database

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

Set client character set

mysqli_set_charset(mysqliLink, charset)

- Description: Set the default character encoding

- Returns: TRUE on success, or FALSE on failure.

Send a MySQL query

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.

Get a row from the result set as an associative array, or a numeric array, or both

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.

Get all rows from the result set as an associative array, an enumerated array, or both

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.

Get the number of rows in the result set

mysqli_num_rows(mysqliResult)

- Note: This command is only valid for SELECT statements.

Get a row from the result set as an associative array

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.

Get the number of record rows affected by the previous MySQL operation

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.

Release the memory associated with the result set

mysqli_free_result(mysqliResult)

- Parameters: mysqliResult is the result set object.

Return the text error message generated by the previous MySQL connection

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!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete