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

bd96500e110b49cbb3cd949968f18be7.png

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 = "";


版权声明:本文为weixin_26805451原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。