如果使用 docker $serverName
使用本机ip
<?php
/* Connect to an ODBC database using driver invocation */
$serverName = '10.37.129.2';
$databaseName = 'test';
$serverPort = '3306';
$username = 'root';
$password = 'thisismymysql1';
if (class_exists('PDO')) {
echo "pdo";
try {
new PDO("mysql:host=" . $serverName . ";dbname=" . $databaseName . ";port=" . $serverPort, $username, $password);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
};
?>
网友评论