PHP code to connect to Mysql database

不言
Release: 2023-03-24 08:52:01
Original
3072 people have browsed it

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 "连接成功";
?>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template