I am trying to use PDO to connect to a MS SQL Server. I have tried using this
$db = new PDO("sqlsrv:server=server;database=databaseName", "username", "password");
I was reading that sqlsrv is no longer supported. I tried using dblib but that is not working.
I wanted to use PDO because it is supposed to work with various databases but I cannot seem to get it to work with MS SQL.
What is the best way to use PDO with SQL Server on Ubuntu?
Any help would be great.
Thanks
Connecting to a MS SQL Server database with PHP is very similar to connecting to a MySQL database. The following example demonstrates how to connect to a MS SQL database from PHP. Note that the function names contain mssql, not mysql.
PDO_DBLIB is a driver that implements the PHP Data Objects (PDO) interface to enable access from PHP to Microsoft SQL Server and Sybase databases through the FreeTDS library. This extension is not available anymore on Windows.
Right now you can get SQL Server 2019 – Standard and Enterprise editions – on both Ubuntu Pro 18.04 LTS and Ubuntu Pro 20.04 LTS, and they come with some solid security and management features as you'd expect – like Transparent Data Encryption (TDE) and Row-Level Security.
SQL Server Express is available for Linux As discussed in Install Microsoft SQL Server 2017 on Fedora 29/CentOS 7, just install the mssql-server package and choose "3) Express (free)" in the configuration step. Show activity on this post. SQL Server Express is available to use in Production.
I figured it out. I guess I forgot that I never installed the SQL/Sybase drivers on this server.
I installed it:
sudo apt-get install php5-sybase
Now I can use:
$db = new PDO("dblib:host=sever;dbname=dbname", "username", "password");
It's working good now.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With