MySQLi 和 PDO 连接 MySQL 实例
作者:互联网
MySQLi 和 PDO 连接 MySQL 实例
实例 (MySQLi - 面向过程)
<?php
$servername = "localhost";
$username = "username";
$password = "password";
// 创建连接
$conn = mysqli_connect($servername,
$username, $password);
// 检测连接
if (!$conn) {
die("Connection
failed: " . mysqli_connect_error());
}
echo "连接成功";
?>
实例 (PDO)
<?php
$servername = "localhost";
$username = "username";
$password = "password";
try {
$conn = new PDO("mysql:host=$servername;dbname=myDB",
$username, $password);
echo "连接成功";
}
catch(PDOException $e)
{
echo $e->getMessage();
}
?>
文章来自 www.dg-haiyue.cn
标签:username,servername,PDO,实例,MySQL,MySQLi,password,连接 来源: https://www.cnblogs.com/96net/p/14917190.html