通过PDO来连接数据库:
<?php
$dsn = 'mysql:dbname=test;host=127.0.0.1';
$user = 'user';
$password = '';
try {
$dbh = new PDO($dsn, $user, $password);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
<?php
$dsn = 'mysql:dbname=test;host=127.0.0.1';
$user = 'user';
$password = '';
try {
$dbh = new PDO($dsn, $user, $password);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
转载于:https://www.cnblogs.com/nizuohao/p/10893604.html