PHP连接数据库模板

<?php
$servername = "119.45.31.120";
$username    = "mwst";
$password     = "123456";
$dbname       = "mwst";

try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

echo 1;//连接成功!
}
catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
$conn = null;
?>

posted @ 2021-05-14 16:43  潘潘-Devil  阅读(119)  评论(0编辑  收藏  举报