1

I want to connect to SQL Server at another pc with php, when i try to connect it says

Connection error: could not find driver

What I have tried is add extension in php.ini.

;extension=php_sqlsrv_56_ts.dll

extension=php_pdo_sqlsrv_72_ts_x64.dll

extension=php_sqlsrv_72_ts_x64.dll

  1. my PHP version is: 7.2.3
  2. SQL SERVER: SQL Server 2014
  3. OS PC: Windows Server 2012 R2 (another pc)

here's my code:

<?php
$host = "192.168.3.126";
$db_name = "dbo";
$username = "david";
$password = "david";
try {
//$con = new PDO("mysql:host={$host};dbname={$db_name}", $username, $password);
$db = new PDO("sqlsrv:Server={$host};Database={$db_name}", $username, $password); 
}
catch(PDOException $exception){ echo "Connection error: " . $exception->getMessage();}
?>

NB: I have download Microsoft Drivers 5.6 for PHP for SQL Server at here, I have download install the ODBC Driver 17 at my own pc

I have tried this reference but it doesn't work PHP Sql Server PDOException:could not find driver

Community
  • 1
  • 1
chopperfield
  • 559
  • 1
  • 7
  • 25
  • 1
    Install both ODBC Driver 17 and PHP extension files (`*_sqlsrv_72_ts_x64.dll`) on one machine (where web server runs). Thanks. – Zhorov Nov 08 '19 at 08:42
  • @Zhorov does the server need to instal xampp? because the server only have SQL SERVER. as for extension where will i put it ? – chopperfield Nov 08 '19 at 09:00
  • In most cases the database server (where SQL Server runs) and the web server (where Apache/IIS and PHP run) are one computer, but yes, they can be two different computers. You need to install PHP Driver for SQL Server on the computer, where the web server runs (XAMPP in your case should be considered as a web server computer). – Zhorov Nov 08 '19 at 09:03
  • You say *"OS PC: Windows Server 2012 R2 (another pc)"* so what is the OS of the server running XAMPP? There is also full documentation on how to install the PHP drivers for SQL Server: [Microsoft Drivers for PHP for SQL Server](https://learn.microsoft.com/en-us/sql/connect/php/microsoft-php-driver-for-sql-server?view=sql-server-ver15) – Thom A Nov 08 '19 at 09:12

0 Answers0