Home > Article > Backend Development > PHP code to connect to Mysql database
This article introduces the code about PHP connecting to the Mysql database. It has certain reference value. Now I share it with you. Friends in need can refer to it
<?php $servername = "127.0.0.1"; $username = "root"; $password = "root"; // 创建连接 $conn = new mysqli($servername, $username, $password); // 检测连接 if ($conn->connect_error) { die("连接失败: " . $conn->connect_error); } echo "连接成功"; ?>
Related recommendations:
PHP script reads local database data
php connection Oracle configuration under windows
The above is the detailed content of PHP code to connect to Mysql database. For more information, please follow other related articles on the PHP Chinese website!