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.
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Mac version
God-level code editing software (SublimeText3)