I cannot create the connection to the database in my php file

Asked

Viewed 597 times

0

I’m trying to connect with the bank but only appears this error:

Fatal error: Uncaught Pdoexception: could not find driver in C: xampp htdocs PDO Example-02.php:3 Stack trace: #0 C: xampp htdocs PDO Example-02.php(3): PDO->__Construct('sqlsrv:Database...', 'user', 'password') #1 {main} thrown in C: xampp htdocs PDO Example-02.php on line 3

I already downloaded the drivers needed for php but it didn’t help. Follow the code (it’s just a simple code to test if you can connect)

<?php
$conn = new PDO( "sqlsrv:Database=db1;server=localhost\SQLEXPRESS;ConnectionPooling=0","usuario", "senha"); 

$stmt = $conn->prepare("INSERT INTO usuario(id, nome) VALUES(1,'Eddy')");

$stmt->execute();
?>

Also follow the drivers used:

extension=php_pdo_sqlsrv_71_nts_x64.dll

extension=php_pdo_sqlsrv_71_nts_x86.dll

extension=php_pdo_sqlsrv_71_ts_x64.dll

extension=php_pdo_sqlsrv_71_ts_x86.dll

extension=php_sqlsrv_71_nts_x64.dll

extension=php_sqlsrv_71_nts_x86.dll

extension=php_sqlsrv_71_ts_x64.dll

extension=php_sqlsrv_71_ts_x86.dll

I’ll be very grateful if you can help me, I’ve been trying to figure this out for a while.

  • 1

    What is your version of PHP? 7.1? and you only need to use one driver. x86 for 32-bit and x64 for 64-bit architecture, also see https://answall.com/a/130889/45722 to see if you need nts or ts

  • My php is 7.1.

  • You added all drivers on php.ini?

  • Yes I added.

  • What is your computer’s architecture? 32-bit or 64-bit?

  • is 64 , so I’ve already put only the 64 drive, have to put in the ext folder ? and then add in php.ini, I’ve already done this and it still makes the same mistake of not finding the drives

  • Yes, you add it to the folder ext/. Just try to add: extension=php_pdo_sqlsrv_71_nts_x64.dll

  • if it doesn’t work, try extension=php_pdo_sqlsrv_71_ts_x64.dll. Of course they need to be in the folder.

  • hasn’t worked yet .

  • Here’s the code with the la part in php.ini

  • ; Be sure to appropriately set the extension_dir Directive. --> Extension=php_pdo_sqlsrv_71_ts_x64 <- Extension=bz2 Extension=Curl Extension=fileinfo

  • I did the following uninstalled php and installed 7.2, now I will have to download other drives or these serve?

  • It’s been a long time since I’ve dealt with PHP, but it’s very likely that you won’t be able to use SQL Server, because the extension is for version 7.1 and it’s not for 7.2 yet. If you find 7.2 drivers, try using them.

  • Okay, thanks for the help.

Show 9 more comments

1 answer

1

I had the same problem as you. Fix by adding to php.ini extensions, I restarted the Wampserver (I’m using this in place of Xamp) and worked properly.

Another thing I did was just leave the dll of x64 I wouldn’t use the x86. I hope I’ve helped.

  • Thank you very much.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.