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;
?>

上一篇:centos7安装apach


下一篇:SQL Server主从配置,端口开放以及服务器改名后的影响