Back

[SOLVED]: Connect to a database through PDO?

  • 0
  • Databases
Maniac_Fighter
29 Mar, 2023, 16:46

So I am trying to add a new database adaptor(Microsoft SQL Server) in the utopia-php/database(https://github.com/utopia-php/database).

I am having trouble connecting through PDO. I tried this

TypeScript
   $dbHost = 'mssql';
                    $dbPort = '1433';
                    $dbUser = 'SA';
                    $dbPass = 'P@ssw0rd';

                    $pdo = new PDO("mssql:host={$dbHost},port={$dbPort}", $dbUser, $dbPass, MsSql::getPDOAttributes());

and it throws this error

TypeScript
PHP Fatal error:  Uncaught PDOException: could not find driver in /usr/src/code/bin/tasks/load.php:217
Stack trace:
#0 /usr/src/code/bin/tasks/load.php(217): PDO->__construct()
#1 {main}
  thrown in /usr/src/code/bin/tasks/load.php on line 217

I did a little bit more googling where I found they suggested a bunch of different host like sqlsrv or dblib but none of them worked.

I tested it without PDO and I am able to connect to the database successfully

Do you have any solution for me. I am pretty sure the url is wrong but I couldn't find the right one?

Links I referred to

  1. https://stackoverflow.com/questions/5953882/how-to-connect-to-mssql-using-pdo-through-php-and-linux
  2. https://stackoverflow.com/questions/32203737/connecting-to-mssql-server-via-php-pdo
TL;DR
Solution: The user was trying to connect to a Microsoft SQL Server database using PDO in a Docker container. The issue was with missing ODBC drivers and SQLSRV and pdo_sqlsrv drivers. The solution was to install the ODBC drivers for Linux or Mac, as well as the SQLSRV and pdo_sqlsrv drivers. These drivers needed to be added to the Dockerfile. After installing the drivers, the user was able to connect to the database successfully.
joeyouss
29 Mar, 2023, 17:05

Hi, allow me to look into this and get back to you, what OS are you on? linux?

joeyouss
29 Mar, 2023, 17:26
Maniac_Fighter
29 Mar, 2023, 19:45

Hey I am on Windows but the containers are working in WSL

About these, these solutions are a bit different the way utopia has architected. Its say to add something in php.ini file (which does not exists in the repo) So I am kinda confused on how to find the driver

VincentGe
29 Mar, 2023, 21:23

There's a proxy in front of Appwrite

VincentGe
29 Mar, 2023, 21:23

Double check Traefik

VincentGe
29 Mar, 2023, 21:24

I'm pretty sure you can't even ping that container without changing config there.

Maniac_Fighter
30 Mar, 2023, 04:30

How do i check that?πŸ˜…

Drake
30 Mar, 2023, 06:11

Maybe you need to install the driver via the docker file. For example, there are some extra libraries needed for mongo: https://github.com/utopia-php/database/blob/b592ab1bab9d7412cf5b756fdcdf850c03b1470d/Dockerfile#L73

VincentGe
30 Mar, 2023, 13:29

πŸ˜… I vaguely recall this was a thing when I tried like a year ago when I just joined. I recall v little detail. If I have time today, I'll try and lyk

Maniac_Fighter
30 Mar, 2023, 15:18

So after a bit more googling and countless build waiting time, I finally figured it out to install those drivers. I was little bit painful but I think it works ( I got different error to fix so that's a progress)

Maniac_Fighter
30 Mar, 2023, 15:28
Maniac_Fighter
30 Mar, 2023, 15:28

[SOLVED]: Connect to a database through PDO?

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more