PHP MSSQL using Apache on Windows and Linux - php

How to setup PHP (5.3/5.4) with MSSQL support on a windows development environment, if applications should be deployed to a linux system? So basically, which driver should be used and how (like using mssql_ functions or PDO or sth.)?
Currently the target system is running PHP 5.1.6 on some CentOS, but this could be updated if needed. We are using the mssql_ functions for database access. I tried to setup the development machine using XAMPP, but had to find out, that the support for MSSQL driver has been dropped in PHP 5.3.
The suggestion seems to be to use sqlsrv driver and functions, but this won't work on the web server.

Use ODBC, the SQLSrv extension is only intended for use on Windows.

Related

Does the mysql client package version on webserver affect PHP queries?

I have two RHEL servers, one to host the PHP application, one to host the MySQL server.
Database server has MySQL Enterprise version 5.6.21 installed.
While getting the application server built, I asked that the rpm MySQL-client-advanced-5.6.21-1.el6.x86_64 be installed (to match server), but the hardware people don't like this version since 5.6.27 is available which addressed some vulnerabilities.
The question is the following:
Does the mysql client version on the application server affect the database queries coming from the PHP application?
We're using PDO to connect to and query MySQL.
If we do this, does the application server even need a mysql client library?
Please let me know if I can clarify.
Thanks!
PHP uses its own library/driver to connect to MySQL databases. The MySQL-client-advanced package is just the CLI mysql client. PHP does not use this.
For PHP (and PDO), you should install php-pdo and php-mysqlnd. php-mysqlnd is the "MySQL native driver" and contains some enhancements. It also contains the mysqli class and the pdo-mysql connector.
Note: php-mysqlnd versions are unrelated to the MySQL server version.
Quote from the Mysql website
MySQL Native Driver is a replacement for the MySQL Client Library (libmysqlclient). MySQL Native Driver is part of the official PHP sources as of PHP 5.3.0.
https://dev.mysql.com/doc/apis-php/en/apis-php-mysqlnd.html

Using ADODB (PHP database library) on OSX

According to the ADODB:
http://adodb.sourceforge.net/
documentation, it can be used for a number of databases on "Unix and Windows", so I'm assuming that includes OSX.
I've enabled PHP in my Apache installation, installed ADODB and modified include_path to include the ADODB directory, however I'm at a loss as to how to enable particular drivers. I have Firebird installed, so I'd prefer to connect to that, however I'm open to using some other database server.
I've managed to work it all out on a Windows install, however there seems to be scant information on how to do it on OSX.

Working with MS SQL SERVER on PHP5.6

So I have a trouble here. Tried use mssql_connect() but interpeter says that function is undefinied. PHP.net advices this, but it suppports only older versions of PHP. Is it possible to connect to MS SQL Server database from PHP5.6? What extensions should I add, what functions can I use?
Configuration details: localhost, Apache 2.4, PHP 5.6, OS Windows 8.
You need to enable the MSSQL extension in the PHP.ini file.
If this extension is not installed, you need to install it in PHP.
Please tell your server details (OS/WebServer like apache nginx) so that I can explain in detail.
Use
<?php phpinfo();?>
to see what are available with your php installation. I advice you to use PDO instead of mysql_* functions. It supports several databases not only MSSQL or MySQL.

How to connect to MSSQL from windows and ubuntu, without writing two sets of code?

My production machine is ubuntu, and my dev machine is windows. If I want to connect to a MSSQL server, from both ubuntu and windows, how do I do it? I'm able to use microsoft's library to connect to the database from my dev machine, but this wouldn't work on the ubuntu machine, correct?
You can use the PDO SQL Server driver from Microsoft when on Windows and the PDO DLIB when on Linux. Other than connecting, you're code will be the same.
If you're unable to use either of those drivers, you'll have to look into PHP ODBC.

PHP MS SQL Unix Driver - Microsoft or FreeTDS

I am running a LAMP server but now need to connect to MS SQL (client request). I have heard Microsoft has a driver, but can't verify if
Does anyone know if the Microsoft driver is available for Unix? If not, should I just stick with FreeTDS? This appears to be recommended by PHP, however install documentation seems lacking. Any direction on either would be greatly appreciated.
Sorry for the general question, I am not familiar with setting up PHP drivers.
UPDATE
Just for some back story, I am running an intranet from the LAMP server but needs to connect to a datasource on an external MS SQL DB Server (Windows of course). I am running PHP5.
FreeTDS is fine and works well enough. The Microsoft driver is Windows only, thus you wouldn't be able to use it on your Linux server.
First install FreeTDS and then configure PHP with --with-mssql=/prefix/used/for/freetds. If you are using your distribution's PHP, I'm sure there is a MS-SQL driver package already precompiled and available for installation (in Ubuntu, that'd be php5-sybase).
Then use PHP's mssql_* functions to actually do the work
For anyone who comes across this rather old question...
It should be noted that since 2010, Microsoft has actually developed a viable Linux driver for SQL Server that is installable via PECL. It's currently only compatible with PHP 7.
The main readme file is here, which lists some general and overly complicated installation instructions. But if you look at the latest release notes you will see that newer versions can be installed via PECL like so:
sudo pecl install sqlsrv
sudo pecl install pdo_sqlsrv

Categories