mySQL PDO Connect
I have tried the other examples shown on the W3C site and I was originally getting a message that the host name/server name was not found. The PDO (Php Data Object) does work after using the connection info that phpMyAdmin was using.
The HTML for php Connect
<?php
$servername = "servername";
$username = "username";
$password = "password";
$myDB = "mydbname";
try {
$conn = new PDO("mysql:host=$servername;dbname=$myDB", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
} catch(PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
?>
The result is above........... Note: the w3-text-colour class is plaoed in a span around the php code (actually an italic with red xlarge text)