Home > Backend Development > PHP Tutorial > Which is the PHP function used to establish a MySQL database connection using PHP script?

Which is the PHP function used to establish a MySQL database connection using PHP script?

王林
Release: 2023-09-01 13:18:01
forward
1311 people have browsed it

Which is the PHP function used to establish a MySQL database connection using PHP script?

PHP provides the mysql_connect() function to open a database connection. This function accepts five parameters and returns a MySQL connection identifier on success and FALSE on failure. The syntax is as follows:

Syntax

connection mysql_connect(server,user,passwd,new_link,client_flag);
Copy after login

The following table shows the parameters used in the above syntax:

##4##new_link5client_flags
Serial number

Parameters and description

1

Server

Optional - The hostname where the database server is running. If not specified, the default is localhost:3306

2

user

Optional - Username to access the database. If not specified, defaults to the name of the user who owns the server process

3

Password

Optional - The password of the user accessing the database. If not specified, defaults to an empty password

Optional - If a second call to mysql_connect() is made with the same parameters, no new connection is established; instead the identifier of the already open connection is returned

Optional - A combination of the following constants:

    MYSQL_CLIENT_SSL
  1. - Use SSL encryption.
  2. MYSQL_CLIENT_COMPRESS
  3. - Use compression protocol.
  4. MYSQL_CLIENT_IGNORE_SPACE
  5. - Allows spaces after function names.
  6. MYSQL_CLIENT_INTERACTIVE
  7. - Allows interaction during the idle time before the connection is closed.

The above is the detailed content of Which is the PHP function used to establish a MySQL database connection using PHP script?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:tutorialspoint.com
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template