PDO MySQL Connection String

Connect to MySQL database using PDO connection string. Please be sure that PDO extension is enable in php.ini file.

$server = "localhost";
$username = "root";
$password = "password";
$dbname = "database_name";

global $conn; //Set global variables so it can be used anywhere in the application.
$conn = null;
$conn = new PDO("mysql:host=$server_ip;dbname=$dbname;", $username, $password); //PDO Connection String
// set the PDO error mode to exception



Leave a Reply

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