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;
?>
标签:servername,数据库,echo,PDO,模板,PHP,dbname,conn,ERRMODE 来源: https://www.cnblogs.com/pan-wang/p/14769144.html