---
title: "Which function is used to connect with database in PHP?"  
description: "Which function is used to connect with database in PHP?"  
author: "zack mathews"  
published: 2016-09-26  
updated: 2020-09-22  
canonical: https://www.mindstick.com/interview/23065/which-function-is-used-to-connect-with-database-in-php  
category: "php"  
tags: ["php"]  
reading_time: 1 minute  

---

# Which function is used to connect with database in PHP?

PHP provides mysqli_connect() function to connect with database. This function has five parameter:

a) Server: The host name running the database. If not defined then by default it is ocalhost.

b) User: The username who is accessing the database.

c) Password: The password given by the user who is accessing the database.

d) new_link(): no new connection will be established.

e) Client_flags : MYSQL_CLIENT_COMPRESS-use Compression protocol.

## Answers

### Answer by KIRTI SHARMA

mysql_connect("Host name","user name","password");

### Answer by zack mathews

PHP provides mysqli_connect() function to connect with database. This function has five parameter:

a) Server: The host name running the database. If not defined then by default it is ocalhost.

b) User: The username who is accessing the database.

c) Password: The password given by the user who is accessing the database.

d) new_link(): no new connection will be established.

e) Client_flags : MYSQL_CLIENT_COMPRESS-use Compression protocol.


---

Original Source: https://www.mindstick.com/interview/23065/which-function-is-used-to-connect-with-database-in-php

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
