PDO MSSQL instead of MySQL

I have been working my way through changing from mysqli to pdo all good but then on the latest site it uses a mssql db, and as soon as I changed the config file with below I got this message -

Fatal error: Uncaught exception 'PDOException' with message 'could not find driver' in \\CSFFILES11\WEBSITES\dev\mysite.php:7 Stack trace: #0 \\CSFFILES11\WEBSITES\dev\new_checksafetyfirst\en\csfintranet\config.php(7): PDO->__construct('mssql:host=csft...', 'contract_user', 'L3tm31n1') #1 \\CSFFILES11\WEBSITES\dev\mysite.php(5): include('\\\\CSFFILES11\\WE...') #2 {main} thrown in \\CSFFILES11\WEBSITES\dev\mysite.php on line 7

Using

$pdo=new PDO("mysql:host=csftest01;dbname=stuff;charset=utf8","user","pass");
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

So thought that a logical change of changing the first line above from mysql to mssql to get

$pdo=new PDO("mssql:host=csftest01;dbname=stuff;charset=utf8","user","pass");
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

But then got this error

Uncaught exception ‘PDOException’ with message ‘could not find driver’ in

Whilst MySQL modules are included in most PHP installs, I don’t suppose MS SQL Server modules are included.

Edit: You can download them here: https://www.microsoft.com/en-us/download/details.aspx?id=20098

1 Like

Are you running on a Windows server?
I think you may want the ODBC driver instead.

http://php.net/manual/en/ref.pdo-sqlsrv.php

The PDO_SQLSRV extension is only compatible with PHP running on Windows. For Linux, see ODBC and » Microsoft’s SQL Server ODBC Driver for Linux.

1 Like

Thank you very much guys, I seem to have connected, but its definitely different to mysql, but at least I’m off the mark.

Thanks again

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.