Ich versuche, eine Datenbank zu verbinden, aber die Fehlermeldung immer sagen:Unable Verbindung zur Datenbank - PHP
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}
Ich benutze XAMPP Apache und MySQL zu laufen. Außerdem habe ich VirtualPorts konfiguriert und auf alle Websites mit ihren Aliasen z. 'mysite /' anstelle von 'localhost'
Könnten Sie bitte den folgenden Code überprüfen und mir helfen, das Problem zu lösen. Danke im Voraus!
<?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';
?>
könnte helfen, sieht aus wie die PDO-Treiber nicht installiert ist. – larsAnders