質問

I am using PHP 5.4.12 on wamp server to connect to a database in another network and it is MSSQL. This database requires to specify the port. I am trying to connect to the DB just to have a result for 2 days and I did not find the answer yet.

my connection code is this:

               <?php

            try {
            $pdo = new PDO("sqlsrv:Server=xx.xx.xxx.173,2020;Database=DB01", "sa", "123456");
            //$pdo = new PDO('mysql:host=localhost;dbname=test;', 'user', 'pass');
            $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

            $pdo->prepare('INSERT INTO DoesNotExist (x) VALUES (?)');
            }   
            catch(Exception $e) {
            echo 'Exception -> ';
            var_dump($e->getMessage());
            }
 ?>

This is my output:
Exception -> string 'could not find driver' (length=21)

Note: I already inserted those files: php_sqlsrv_54_ts.dll php_pdo_sqlsrv_54_ts.dll

because I have in my php folder php5ts.dll

I read one topic here in stackoverflow that this might is a problem of wamp server 64 bits, but this is a post of 2013, they still didnt fix it?

役に立ちましたか?

解決

Finally get this working.

I had installed the WampServer 64 bits in my machine and WampServer 64 does not have dll for MSSQL or something like this. When I was uninstalling the 64bits and after installing the 32 bits, some files permanence there. This is what you should do:

1- Uninstall the 64 bits.
2- Delete all the files in the , usually located in (C:/wamp), make a backup of your "www" folder
3- Restart your computer
4- Install the WampServer 32bits
5- Follow this tutorial that is really good, and clearly. But he uses Xampp, the difference is only the location of the folders. http://www.channaly.info/connect-to-microsoft-sql-server-2005-2008-with-php/

Note: If you are not sure of the sqlsrv.dlls are working, just EXIT wamp server and open it again. If have some problem with your .dll file, It gonna pop up a message to you. If does not pop up any message, You have it installed successfully OR you did not COMPLETELY installed.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top