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 to MySQL database in PHP

2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to connect MySQL database in PHP". The explanation content in the article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian slowly and deeply to study and learn "how to connect MySQL database in PHP" together!

mysqli connect database $servername="localhost";$username="root";$password="root";$dbname="name1";$link = mysqli_connect($servername, $username, $password, $dbname);if (mysqli_connect_errno()) { printf("connection failed: %s\n", mysqli_connect_error()); exit();}echo "Connection successful". "";

If the connection is successful, it will output connection success, if the connection fails, it will output connection failure.

pdo Connect database $host='localhost';$dbname=' name1';$username='root';$password=' root';$pdo=new PDO("mysql:host=$host;dbname=$dbname",$username,$password);echo "Connection successful". "";?>

As above, if the connection is successful, it will output connection success, if the connection fails, it will output connection failure.

Thank you for reading, the above is "PHP how to connect MySQL database" content, after the study of this article, I believe we have a deeper understanding of PHP how to connect MySQL database this problem, the specific use of the situation also needs to be verified. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!

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

Development

Wechat

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

12
Report