Syntax error Which PHP function is used to establish MySQL database connection using PHP script?

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



PHP provides mysql_connect() function to open a database connection. This function takes five parameters and returns a MySQL link identifier on success or FALSE on failure. Its syntax is as follows −

Syntax

connection mysql_connect(server,user,passwd,new_link,client_flag);

Following table give us the parameters used in the syntax above −

Sr.No
Parameter & Description
1
Server
Optional − The host name running the database server. If not specified, then the default value will be localhost:3306
2
User
Optional − The username accessing the database. If not specified, then the default will be the name of the user that owns the server process
3
Passwd
Optional − The password of the user accessing the database. If not specified, then the default will be an empty password
4
new_link
Optional − If a second call is made to mysql_connect() with the same arguments, no new connection will be established; instead, the identifier of the already opened connection will be returned
5
client_flags
Optional − A combination of the following constants −
  1. MYSQL_CLIENT_SSL − Use SSL encryption.
  2. MYSQL_CLIENT_COMPRESS − Use compression protocol.
  3. MYSQL_CLIENT_IGNORE_SPACE − Allow space after function names.
  4. MYSQL_CLIENT_INTERACTIVE − Allow interactive timeout seconds of inactivity before closing the connection.
Updated on: 2020-06-22T13:23:44+05:30

223 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements