Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to connect PHP and MYSQL database

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "how to connect PHP and MYSQL database". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn how to connect PHP and MYSQL databases.

Among the many functions in the MYSQL database, there are two functions used to connect: MysQL-connect () and MySQL__pconnect (). The syntax is as follows:

Int MySQL-connect (string [hostname] (: [Port,string [username], string [password]) int MySQL__pconnect (string [hostname] (: [Port,string [username], string [password]) both functions return a connection number when the connection is successful, or a false value if it fails. Among the parameters, the hostname (hostname) can contain the port number (port) of the database service, usually using the default port number. If all parameters are filled in, the default hostname is "localhost", the user name (username) is the database administrator, the default is "root", and the Password is empty.

When establishing a connection using MysQL connect (), the established connection is automatically closed after the operation of the database is completed, unless the connection has been forcibly closed using MySQL-close () before that. Using MysQL-pconnect () automatically checks whether there is a connection with the same hostname, user name, and password each time you connect, and if so, directly uses the connection number for that connection. Also, using MySQL-pconnect () is a solid and persistent connection that does not stop because the operation of the database stops. And it will not be terminated by the function MySQL_commect ().

Program example:

Echo "$connect"

? >

The running result of the program is: (1). This shows that the program is already connected to the database.

At this point, I believe you have a deeper understanding of "how to connect PHP and MYSQL databases". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report