Home  >  Article  >  Backend Development  >  How to check whether php is connected to the database

How to check whether php is connected to the database

(*-*)浩
(*-*)浩Original
2019-09-04 10:58:495948browse

How to connect to the php database and how to determine whether the database connection is successful.

How to check whether php is connected to the database

Create a new php file (recommended learning: PHP video tutorial)

How to check whether php is connected to the database

## Set variables and use the mysql_connect() function to connect to the database. The parameters in brackets are the database address, user name and database password

How to check whether php is connected to the database

The database is connected. Then the database has What if the link is not successful?

Judge by if

How to check whether php is connected to the database

If the connection is successful, output: Database connection is successful

How to check whether php is connected to the database

If the database is not connected to the output die() function, the database connection fails and mysql_error() is used to output the error

How to check whether php is connected to the database

The above is the detailed content of How to check whether php is connected to the database. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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