如何通过PHP脚本代码连接mysql数据库?

问题描述:

我有通过php连接数据库的脚本。其实我想与mysql数据库建立连接。我尝试使用以下脚本在phpDesigner8软件上运行,但它总是提供输出OOPs出错,表示没有建立连接。脚本或任何代码行中是否有任何错误。

错误显示,

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:

<pre><?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;
servername = "localhost";


username =root;
username = "root";


password =;
password = "";