PHP 连接本地mysql

 

<?php
echo microtime(true);
?>



<?php
$servername = "localhost";
$username = "root";
$password = "111111";

// 创建连接
$conn = new mysqli($servername, $username, $password);

// 检测连接
if ($conn->connect_error) {
    die("连接失败: " . $conn->connect_error);
}
echo "连接成功";
?>



<?php
$servername = "localhost";
$username = "root";
$password = "111111";

try {
    $conn = new PDO("mysql:host=$servername;", $username, $password);
    echo "连接成功";
}
catch(PDOException $e)
{
    echo $e->getMessage();
}
?>

 

 

上一篇:php-mysql脚本失败时如何获取详细的错误报告?


下一篇:UVA11459 HDU3168 Snakes and Ladders【Ad Hoc】