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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics



PHP development practice: Use PHPMailer to send emails to users in the MySQL database Introduction: In the construction of the modern Internet, email is an important communication tool. Whether it is user registration, password reset, or order confirmation in e-commerce, sending emails is an essential function. This article will introduce how to use PHPMailer to send emails and save the email information to the user information table in the MySQL database. 1. Install the PHPMailer library PHPMailer is

As the amount of data continues to increase, database performance has become an increasingly important issue. Hot and cold data separation processing is an effective solution that can separate hot data and cold data, thereby improving system performance and efficiency. This article will introduce how to use Go language and MySQL database to separate hot and cold data. 1. What is hot and cold data separation processing? Hot and cold data separation processing is a way of classifying hot data and cold data. Hot data refers to data with high access frequency and high performance requirements. Cold data

To resolve the plugin not showing installed issue in PHP 7.0: Check the plugin configuration and enable the plugin. Restart PHP to apply configuration changes. Check the plugin file permissions to make sure they are correct. Install missing dependencies to ensure the plugin functions properly. If all other steps fail, rebuild PHP. Other possible causes include incompatible plugin versions, loading the wrong version, or PHP configuration issues.

How to use MySQL database for time series analysis? Time series data refers to a collection of data arranged in time order, which has temporal continuity and correlation. Time series analysis is an important data analysis method that can be used to predict future trends, discover cyclical changes, detect outliers, etc. In this article, we will introduce how to use a MySQL database for time series analysis, along with code examples. Create a data table First, we need to create a data table to store time series data. Suppose we want to analyze the number

As the amount of data increases, database backup becomes more and more important. For the MySQL database, we can use the Go language to achieve automated incremental backup. This article will briefly introduce how to use Go language to perform incremental backup of MySQL database data. 1. Install the Go language environment. First, we need to install the Go language environment locally. You can go to the official website to download the corresponding installation package and install it. 2. Install the corresponding library. The Go language provides many third-party libraries for accessing MySQL databases, among which the most commonly used ones are

Common solutions for PHP server environments include ensuring that the correct PHP version is installed and that relevant files have been copied to the module directory. Disable SELinux temporarily or permanently. Check and configure PHP.ini to ensure that necessary extensions have been added and set up correctly. Start or restart the PHP-FPM service. Check the DNS settings for resolution issues.

To what extent can I develop MySQL database skills to be successfully employed? With the rapid development of the information age, database management systems have become an indispensable and important component in all walks of life. As a commonly used relational database management system, MySQL has a wide range of application fields and employment opportunities. So, to what extent do MySQL database skills need to be developed to be successfully employed? First of all, mastering the basic principles and basic knowledge of MySQL is the most basic requirement. MySQL is an open source relational database management

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...
