Code has been added to clipboard!
MySQL Connecting With PHP Data Objects
Example
<?php
$servername = "localhost";
$username = "name_of_the_user";
$password = "users_password";
try
{
$conn = new PDO("mysql:host=$servername; dbname=myDatabase", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);Â Â Â
echo "Connected successfully";
}
catch(PDOException $e)Â Â Â
{Â Â Â
echo "Failed to connect: " . $e->getMessage();Â Â Â
}
?>