Home  >  Article  >  Backend Development  >  PHP code to connect to Mysql database

PHP code to connect to Mysql database

不言
不言Original
2018-04-17 15:50:463070browse

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!

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