gpt4 book ai didi

php - 无法连接到数据库 - PHP

转载 作者:行者123 更新时间:2023-11-29 21:09:33 25 4
gpt4 key购买 nike

我正在尝试连接到数据库,但收到错误消息:

PDOException: could not find driver in E:\Drive\Dev\PHP\connect\index.php:3 Stack trace: #0 E:\Drive\Dev\PHP\connect\index.php(3): PDO->__construct('mysql:host=localhost;...', 'dbuser', 'dbpassword') #1 {main}

我使用 XAMPP 来运行 Apache 和 MySQL。我还配置了 VirtualPorts 并通过别名访问所有网站,例如'mysite/' 而不是 'localhost'

请您检查下面的代码并帮助我解决问题。提前致谢!

<?php
try{
$pdo = new PDO('mysql:host=localhost;dbname=carbrands', 'dbuser', 'dbpassword');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->exec('SET NAMES "utf8"');
}
catch(PDOException $e){
$output = 'not connected';
$e->getMessage();
include 'output.html';
exit();
}

$output = 'connected';
include 'output.html';
?>

最佳答案

看起来您缺少正确的驱动程序。

检查这个答案,因为它可能对您有帮助

Missing driver

关于php - 无法连接到数据库 - PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36510001/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com