Connecting to SQL server database with PHP and Windows drivers - php

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!

Related

SQL Server setup with PDO on Redhat

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);

How to get SQLSRV on Xampp working with Medoo?

I got a PHP project which uses Medoo for accessing a database on MS SQL Server 2012. I used to test my project on the same server, but since copy-pasting through remote desktop got kinda annoying and inefficient, I wanted to move on a local system, so I installed Xampp (with PHP 5.6.19 VC11). Since I still need to use the server database, I first encountered the problem that the PDO MSSQL extension is not available anymore, and my script failed to send a query to the database. So tried using the SQLSRV 3.0 extension instead (5.4 thread-safe - why isn't there a version 5.6? Is 5.4 supposed to be forward compatible?), which still sends me an uncaught exception with message 'could not find driver', thrown from the PDO constructor and forwarded through Medoo. I'm not sure if this fails on Medoo, the driver, or something else. Moving the database to phpMyAdmin is no option... Has anyone an idea how I can solve this?
All information you need are on this this web page https://msdn.microsoft.com/en-us/library/cc296170(v=sql.105).aspx.
As you can see you need version 3.2 for PHP 5.6 support. I found download link and information about adding SQLSRV extension to php.ini for you.
https://www.microsoft.com/en-us/download/details.aspx?id=20098
https://msdn.microsoft.com/en-us/library/cc296203(v=sql.105).aspx
Finally you have to install Microsoft ODBC Driver 11 for SQL Server.
In short, download SQLSRV 3.2, add PDO extension to php.ini (choose right version for your PHP), install Microsoft ODBC Driver 11 for SQL Server on your local enviroment.

Connect to Oracle with PHP via ODBC

I'll start off by saying I am thoroughly confused. I've read through "The Underground PHP and Oracle Manual White Paper" and through some similar questions on StackOverflow and I still have no idea what I need to do.
I'm using PHP 5.3.1 on Ubuntu 12.04. I'm trying to connect to Oracle 11g. I don't know if I need Instant Client or Oracle XE. I want to connect to it using PDO as that's how my code is already structured but I can't make heads or tails of the documentation. I also have an option to connect via ODBC. Any help would be greatly appreciated.
In any way, you need at least instant client if you are connecting with PDO.
Oracle XE contains OCI runtime (Oracle call interface), but you may need to setup some environment variables to make it work.
Is it Oracle XE instance on same server as Apache/PHP ?
You have couple of good articles on google's search result like:
http://www.sitepoint.com/oracle-10g-xe-and-php/
http://docs.oracle.com/cd/E17781_01/appdev.112/e18555/ch_one.htm
http://web3us.com/drupal6/how-create-web-site-handbook/oracle-xe-php [Recommended reading]
http://www.devshed.com/c/a/Oracle/Configuring-Oracle-Database-XE-and-PHP/
http://php.net/manual/en/function.oci-connect.php

Sqlserv extension on mac

My company uses the sqlserv extension to connect to a MSSQL database. This extension was chosen over the mssql extension because it is actively being maintained by Microsoft and the mssql driver is no longer maintained at all. My colleague has always worked in a windows enviroment so he could just download the proper DLL file and voila, sqlserv is available. Since i am running on Mac OSX 10.8.1 i don't share this luxery.
So basically the question is: does anyone know of a sqlserv php extension in the form of a .so file?
You cannot run the SQLSRV extension on anything other than Windows as stated here:
http://php.net/manual/en/sqlsrv.installation.php
However, even if you could, I would strongly urge you to stay away from the SQLSRV extension as it is extremely buggy and underdeveloped. You would be much better off using PDO!
I spent days trying to work out which extension to use, and after much research and questions on stackoverflow, it was clear that PDO was the only realistic solution for connecting to an MSSQL database. Not to mention the additional functionality that you have!
Try and execute stored procedures, return multiple recordsets along with output parameters using the SQLSERV extension!! Just one of the many features that can be done in a few lines with PDO but cannot be done with SQLSERV.
Furthermore, PDO is faster!

mssql_connect no longer working as of PHP 5.3

I just received an email from our host and they've upgraded our PHP to 5.3, unfortunately though, all the scripts have now broken. I traced it down to the function mssql_connect failing. Support told me this has now been deprecated under 5.3 - how can this be true?
How can you connect to a mssql database under PHP 5.3 now??
http://www.php.net/manual/en/intro.mssql.php
"This extension is not available anymore on Windows with PHP 5.3 or later."
Maybe you should look into converting your app to use PDO:
http://www.php.net/manual/en/ref.pdo-sqlsrv.php
If you see such a warning, the first place to visit is the PHP documentation.
From http://php.net/manual/en/intro.mssql.php:
Introduction
These functions allow you to access MS SQL Server database.
This extension is not available anymore on Windows with PHP 5.3 or
later.
SQLSRV, an alternative driver for MS SQL is available from Microsoft:
ยป http://msdn.microsoft.com/en-us/sqlserver/ff657782.aspx.

Categories