0

I have a very simple PDO connection that I am trying to get connected to a db in xampp. On my laptop, xampp works and this code runs fine and connects to the db, but on my desktop I've installed xampp and tried the same code (same repo) and it spits out an error (could not find driver)

If anyone else has had this exact issue and has solved it, please help

Windows 11, xampp version 8.2.0

Much appreciated.

`<?php
$servername = "localhost";
$username = "root";
$password = "";

try {
  $conn = new PDO("mysql:host=$servername;dbname=oopphptest1", $username, $password);
  // set the PDO error mode to exception
  $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  echo "Connected successfully";
} catch(PDOException $e) {
  echo "Connection failed: " . $e->getMessage();
}`

Ive spend the last couple of days researching this error and I have tried many of the solutions, uncommenting extentions in the php.ini file, uninstalling and reinstalling xampp and so on...

I also get this error, even when xampp isn't running (the usual error is: SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it), but even then it just spits out could not find driver whether xampp is running or not.

After searching in phpinfo(); under PDO, values are set and it is enabled...

  • It seems you are running this code using some other software, not xampp. I mean, when xampp is not running, your PHP code won't be executed at all. but given it works and gives you an error, it runs using some other webserver, not xampp. – Your Common Sense Mar 23 '23 at 05:37
  • To anyone out there who is looking for a solution! I just found it! I use VSCODE, and in VSCODE I use an extension, "PHP SERVER"... I cleared the PHP Config Path and PHP Path settings in that extension and that fixed my problem... – Thomas Cottis Mar 23 '23 at 22:32

0 Answers0