Detailed explanation of php mysqli operation mysqli_connect to connect to the database instance

怪我咯
Release: 2023-03-05 09:58:02
Original
9202 people have browsed it

PHP must first connect to the specified database to operate the database. The mysql_connect function we used before is no longer supported by some PHP versions. Currently, the editor uses the mysqli_connect function to link to the database. The usage is the same as mysql Basically similar.This article introduces how to use the mysqli_connect function and examples. Friends who need it can refer to

## Recommended related mysql video tutorials: "mysql tutorial"

Introduction to mysqli_connect

php mysqli

_connect is used to connect to the mysql server. This function has multiple parameters and the syntax is as follows

mysqli_connect(host,username,password,dbname,port,socket);
Copy after login

The parameters are as follows:

host Optional. Specify the hostname or IP address.

username Optional. Specifies the MySQL username.

password Optional. Specifies the MySQL password.

dbname Optional. Specifies the database to use by default.

port Optional. Specifies the port number to attempt to connect to the MySQL server.

socket Optional. Specifies the socket or named pipe to use.

But we generally only need to know the following four parameters:

host Optional. Specify the hostname or IP address.

username Optional. Specifies the MySQL username.

password Optional. Specifies the MySQL password.

dbname Optional. Specifies the database to use by default.

mysql_connect instance

Copy after login

If the connection is successful, a MySQL connection ID is returned. If the connection fails, FALSE is returned.

This is the usage of mysqli_connect(), which is very close to mysql_connect. In other words, there is just one more i difference.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!