Created
August 14, 2019 01:35
-
-
Save martin-mok/4fd88dc5ed0ec0fadb001af88169c3f0 to your computer and use it in GitHub Desktop.
php code to connect mysql wtih different port
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//for default MySQL port 3306 | |
//$servername = "127.0.0.1"; | |
//for MySQL deployed on port 3308 | |
$servername = "127.0.0.1:3308"; | |
$username = "root"; | |
$password = ""; | |
try { | |
$pdo = new PDO("mysql:host=$servername;", $username, $password); | |
// set the PDO error mode to exception | |
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); | |
echo "Connected successfully"; | |
echo $pdo->query('select version()')->fetchColumn(); | |
} | |
catch(PDOException $e) | |
{ | |
echo "Connection failed: " . $e->getMessage(); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment