Home  >  Article  >  Backend Development  >  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?

王林
王林forward
2023-09-01 13:17:061265browse

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);

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!

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