SQL Server setup with PDO on Redhat - php

I am currently creating a PHP script to copy some data onto a Microsoft SQL server from a MySQL server. I decided to use PHP with PDO since I thought it would be a really quick process (famous last words).
The Mysql side is completed but I am completely stuck on the MS SQL side on how to get everything installed correctly. My work script server has several different drivers installed (freeTDS, Microsoft ODBC Drivers) and I am not sure how to setup this new MS SQL server in PHP especially to use PDO instead of the direct ODBC functions PHP has.
The work server uses PHP 5.3 which has caused problems with perl rejecting to install sqlsrv/pdo_sqlsrv since the server doesn't run PHP 7.1 or greater.
My main questions being:
Which driver should I use to setup the PHP 5.3 MSsql driver on a redhat server that will work with PDO?
What should my PDO connection string look like?
This is what I have now:
$connectString = "sqlsrv:server=$host;Database=$schema;charset=$charset";
Is it really necessary to define the server connection in the ODBC driver before hand?
Sorry I don't have more research into this it seems there are many ways to bring in MSsql in PHP and I'm not sure which path to go down for my specific version of PHP!

I use this for MSSQL connection with pdo
$db = new PDO("sqlsrv:SERVER=$dbhost;DATABASE=$dbname", $dbuser, $dbpassword);

Related

PHP Problem connecting php and .mdb with pdo-odbc

I have php program that requires MS Access, so I had to use odbc. Locally, using DSN it was working fine:
$db = new PDO("odbc:MyDSN");
I also have no problem when I put the php and odbc at the server and access it remotely:
$db = new PDO("odbc:DRIVER=MDBTools; DBQ=Data.mdb;");
But I can't afford to use it for some reason. I want to put php on the server together with the database but I want to place odbc (or the odbc driver) on the client, something like this:
$db = new PDO("odbc:{127.0.0.1\foo\bar\odbc.ini}; DBQ=Data.mdb;");
I can't seems to work with it for a while. I'm using Ubuntu 64bit as server, and Windows 7 as client
UPDATE 1: I found a way to do it, but it needs to modify the PHP itself (Classes,structure,etc.) I hope someone can help me to get alternative solutions
UPDATE 2: Another solution, but requires third party software.
But I can't afford to use it for some reason. I want to put php on the
server together with the database but I want to place odbc (or the
odbc driver) on the client, something like this:
The driver must be loaded by PHP, which is the "client" in this scenario. Means, you'll have to find an appropriate MSAccess ODBC driver for Ubuntu.
Check this SO thread:
ODBC connection to MS-Access on Ubuntu

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

Connecting to SQL server database with PHP and Windows drivers

I was trying to connect to a Microsoft SQL Database with PHP using the mssql set of functions that WERE in php. Since I am using php 5.5, these functions are deprecated I think, but I read that there is a solution, which is downloading the drivers windows is providing. I downloaded and installed them from the following link:
https://www.microsoft.com/en-us/download/details.aspx?id=20098
Now the only thing is unclear to me is how to use them. Do these drivers re-activate the mssql (which I am sure it is not the case since I tried the code using mssql_connect and it threw a php error saying that the function could not be found)?
Can anybody give me an example of a MSSQL connection with these drivers?
Thanks a lot for your time and help!
Cheers!

Connecting to MS SQL Server in PHP

I'm running a WAMP stack and and trying to connect to an SQL Server instance with PHP's PDO.
I've downloaded the PHP drivers for MS SQL from here and added **php_pdo_sqlsrv_54_ts.dll** into PHP's extension folder.
Then added "php_pdo_sqlsrv_54_ts.dll" to the list of extensions in php.ini.
I know I'm using the correct driver because I'm using PHP version 5.4.3 and **phpinfo()** reports that it's thread-safe.
However, after restarting Apache **phpinfo()** (and **PDO::getAvailableDrivers()**) both report that only the mysql, odbc and sqlite PDO drivers are loaded.
This means that when I attempt to connect to my SQL Server instance I get the error:
could not find driver
Can anyone advise on how to get this working?
Sounds like the SQL Native Client is missing.
System Requirements
Microsoft SQL Server 2012 Native Client available in the SQL Server 2012 Feature Pack.

Using sqlsrv_connect on Platforms other than Windows

I've inherited some code that uses the sqlsrv_connect method to instantiate a connection to a SQL Server database. My personal development machine is an OS X box that I'm running apache an PHP on. I have an instance of SQL Server running in a virtual machine.
When I attempt to connect to the database, I get the following error.
Fatal error: Call to undefined function sqlsrv_connect() in ...
It appears that sqlsrv_connect is not part of standard PHP, and is part of a driver that ships with SQL Server 2005. (please correct me if I'm wrong here)
Is there a way to use this function on Non-Windows platforms? I realize I could install/build an Apache/PHP instance on my Windows machine, but if there's a way to get this function working on OS X (or other *nixes) I'd prefer it.
Is not possible. The SQL Native Driver for PHP is Windows only product:
The SQL Server Driver for PHP relies
on the Microsoft SQL Server 2005 ODBC
Driver to handle the low-level
communication with SQL Server. As a
result, the SQL Server Driver for PHP
is only supported on Windows.
You can look here for a tutorial on how to install the extension. (Via Google)
I'm not too famillar with the extension, but that source should be able to help you out.
(Updated Link to Better Source, still via Google)
The SQL Server Driver for PHP (from MS) is available only on Windows. Unless you want some specific features offered by this driver/ API, you can use the PHP ODBC module along with UnixODBC/ iODBC driver, or FreeTDS (ODBC or db-lib)

Categories