I am doing tests with a local sql server express that I have on my computer.
Then I have xamp installed and in the htdocs folder I have the php code to try to extract data from the database. It gives me the following Error:
Fatal error: Uncaught PDOException: could not find driver in C:\xampp\htdocs\php\selectall.php:3 Stack trace: #0 C:\xampp\htdocs\php\selectall.php(3): PDO->__construct ('sqlsrv:Server=D...', 'root', '') #1 {main} thrown in C:\xampp\htdocs\php\selectall.php on line 3
It's probably high as simple as misusing the username and password.
Being local I don't know if I should use the IP I have (172.26.0.93) and I don't know what password.
Use loscalhost and password empty or root
OR use hostname and connection as I do in managment:
PHP code:
<?php
//---------------------------------Consulta Agenda---------------------------------
$pdo = new PDO("sqlsrv:Server=DESKTOP-6C68BFU\SQLEXPRESS;Database=Inventario", "root", "");
$statement = $pdo->prepare("SELECT [NOMBRE]
,[MODELO]
FROM [Inventario].[dbo].[MARCA]");
$statement->execute();
$results = $statement->fetchAll(PDO::FETCH_ASSOC);
echo json_encode($results, JSON_UNESCAPED_UNICODE);
?>
It gives you a driver error, not a user/password or host error.
If you have the latest version of XAMPP, it is most likely that you actually have the driver installed since it is included in the latest versions of PHP (7.0, 7.1 and 7.2) as indicated in the latest release of the repository:
Make sure you have it uncommented in your php.ini. Search for sqlsrv and make sure the line does not have a semicolon in front of it.
I leave you a link with the explanation on the subject of the Driver PHP SQL Server driver .