I have script to connect database by in php. Actually I want to make connection with mysql database. i tried the following script to run on phpDesigner8 software but it always gives output "OOPs something went wrong" which denotes that connection is not made. Is there anything wrong in script or any code line missing.
error shows,exception 'PDOException' with message 'could not find driver' in E:\admin softs\website_demo\~config.inc.php:10 Stack trace: #0 E:\admin softs\website_demo\~config.inc.php(10): PDO->__construct('mysql:host=loca...', 'root', '') #1 {main}
Please help me. thanks.
What I have tried:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "9tutorial";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e)
{
die("OOPs something went wrong");
}
?>
解决方案servername = "localhost";
username = "root";
password = "";