Slim2 : could not find driver

Hello everybody,

I’m facing a problem with my slim 2 application and I hope that any of you can point me in the right direction,.

I’m developing an angularjs solution and my development enviroment is this :

windows 8.1
IIS
php 5.6 ( x86-NTS-VC11)
ms sql server 2014 express
php_sqlsrv_56_nts.dll
php_pdo_sqlsrv_56_nts.dll

I have developed my api with Slim 2 and it’s working fine when I query my database (GET).
When I going to make an update (PUT) I get an error ( “could not find driver”) in my db connection function (new PDO…).

function getConnection() {
$serverName = “(local)\sqlexpress”;
$conn = new PDO( “sqlsrv:server=$serverName ; Database=mydatabase”, “myuser”, “mypassword”);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $conn;
}

I call the same function for my GET requests and it works nicely.
I’m not an MS SQL expert but it seems to me that the user owns all the permissions to update the table.

Should I change my connection string?
Is Slim acting different if the connection is opened for a PUT operations ?

Thanks a lot

I have no experience with ms sql server, but I doubt this issue has anything to do with Slim. There is no relation between the request method and a pdo connection.

Is it possible that you’re not using the database when calling the GET route (cache maybe)?

That error means that you don’t have pdo_mysql.
Look in phpinfo() for pdo_mysql, PDO Driver for MySQL, maybe you have it installed but disabled

Anyway with phpinfo you should see if something is not being loaded for some reason

Thanks for the replies.

I confirm that I’m able to query the MS SQL database with GET request.
I have also updated some data inside a GET request, so I’m sure that my drivers are ok.
The problem arise only when I create the PDO inside a PUT request.
In example I wrote this test function:

$app->put('test_put/:id, function($id){
   $db=getConnection();
   echo "test_put";
})

and I get this message with postman:

Slim Application Error
The application could not run because of the following error:
Details

PDOException
Message: could not find driver

C:\inetpub\wwwroot\api\api.php

Line: 511

Trace

C:\inetpub\wwwroot\api\api.php(511): PDO->__construct('sqlsrv:server=(...', 'myuser', 'mypassword')
#1 C:\inetpub\wwwroot\api\api.php(28): getConnection()
#2 [internal function]: {closure}('1')
#3 C:\inetpub\wwwroot\api\Slim\Route.php(468): call_user_func_array(Object(Closure), Array)
#4 C:\inetpub\wwwroot\api\Slim\Slim.php(1357): Slim\Route->dispatch()
#5 C:\inetpub\wwwroot\api\Slim\Middleware\Flash.php(85): Slim\Slim->call()
#6 C:\inetpub\wwwroot\api\Slim\Middleware\MethodOverride.php(92): Slim\Middleware\Flash->call()
#7 C:\inetpub\wwwroot\api\Slim\Middleware\PrettyExceptions.php(67): Slim\Middleware\MethodOverride->call()
#8 C:\inetpub\wwwroot\api\Slim\Slim.php(1302): Slim\Middleware\PrettyExceptions->call()
#9 C:\inetpub\wwwroot\api\api.php(32): Slim\Slim->run()
#10 {main}

Just to inform you that I finally found the cause of the problem.
As rightly noted JoeBengalen Slim has nothing to do with the problem.
After successfully configuring the Handler Mappings in IIS 7 now everything works perfectly.
For reference : https://technet.microsoft.com/en-us/library/hh831697(v=ws.11).aspx#Request_Restrictions