Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP PDO to MS SQL Server on Ubuntu Server

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

like image 980
Sequenzia Avatar asked Sep 26 '12 05:09

Sequenzia


People also ask

Can I connect PHP to SQL Server?

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.

What is Pdo_dblib?

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.

Can I use SQL Server on Ubuntu?

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.

Can SQL Server Express run on Linux?

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.


1 Answers

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.

like image 120
Sequenzia Avatar answered Oct 12 '22 20:10

Sequenzia