Categories
tech

MySQL connection string via PDO

The simple example to test connection via PDO is below:

<?php
$servername = "database server";
$username = "username";
$password = "password";
 
try {
    $conn = new PDO("mysql:host=$servername;", $username, $password);
    echo "connected!"; 
}
catch(PDOException $e)
{
    echo $e->getMessage();
}
?>

1 reply on “MySQL connection string via PDO”

Leave a Reply

Your email address will not be published. Required fields are marked *