如何通过PHP脚本代码连接mysql数据库? [英] How to connect with mysql database by PHP script code?

查看:125
本文介绍了如何通过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 = "";


这篇关于如何通过PHP脚本代码连接mysql数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆