MDB2 With SQL Express 2008 - php

So basically here's my problem. I'm looking for a solution to allow us to connect with SQL Express 2008, while still using MDB2 as our database abstraction layer. I need something like this, mainly because we still need to be able to use MySQL and Postgres (and ORMs seem to be not an option at this point in time).
Preferably, there would be a solution that works for both PHP5.2 and PHP5.3.
At first I went down the php_mysql extension road... it seems, though, as though that is not available in PHP 5.3.
php_pdo_mssql doesn't seem to be usable with MDB2, so that seems to be out.
Finally, there's the MS developed 'SQLSRV' extension, and while it seems as though there was work on a MDB2 'extension' for it at one point, it doesn't seem to have ever made it into the main branch.
Please... does anyone have any solutions for me?

For anyone else looking for information on this... so far, I have got SQL Express 2008 working with MDB2 running under PHP 5.2.
I have not yet tried connecting to a remote server: so far, I have only connected to SQL Express running on localhost.
I'm not sure if the PHP I am using shipped with the php_mssql.dll extension or not: either way, I disabled it. Instead, I used the php_dblib.dll that I downloaded from links on http://docs.moodle.org/en/Installing_MSSQL_for_PHP . This library is a build of FreeTDS (from freetds.org). I have not done any major testing with it yet, but I can connect to it, and I have been told by a colleague that they are having 'actual' success with it.
php_dblib.dll provides 'replacement' functions for the mssql_* functions that php_mssql.dll provided. Therefore, you need to disable the php_mssql.dll extension before enabling the php_dblib.dll one.
Other little things to note:
1) whereas most documentation on SQL Express and PHP state that you have to include the 'instance' name in the host section of the DB connection information, I found that this did not work for me: in fact, I had to explicitly remove the "\SQLEXPRESS".
2) while the Moodle link above provides PHP 5.3 builds of php_dblib.dll, unfortunately they are built with VC9. The install of PHP 5.3 I have was built with VC6 and so I am still working on building my own php_dblib.dll for PHP 5.3.
Anyway, I hope that this helps people who are having the same problem.

Related

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!

PHP PDO Failure to open stream

I'm sure this is something simple that I'm overlooking, but it's driving me a bit crazy. I'm on a Ubuntu machine running LAMP. I have several sites running on this machine using Php / MySql without a hassle. I've recently begun a site using the Yii framework, but I don't think that this is a Yii quesiton. Maybe it is. Anyway...
My other sites used mysqli so Yii's PDO requirement is new to me. I did a quick -i|grep on the PDO and it came back as installed / enabled so no worries. I installed the framework, created a quick test site and database. However, when I try to connect to the database via the site I get an error telling me that the PDO failed. Specifically, a failure to open the stream. So it's not finding the PDO even though the PDO is installed. The Yii site is in the same web folder as the other sites, so there can't be a path issue.
From a Yii standpoint, if that is where the problem lies... I was able to create controllers for the various database tables in Gii, but pulled the same unable to open stream error when I tried to generate CRUD for those tables.
For the record, yes, the MySql is enabled in the Yii main.php file. Yes, the connection string is correct. I'm a bit at a loss as to why the PDO would fail to open if it lists as enabled.
Posting this just for the search engines. I still have no idea exactly what the problem might have been. As I mentioned, PDO was showing enabled from the CLI, but not from phpinfo. This is possible because the CLI uses a different php.ini than does apache2. However, after a complete re-install of php I was still running into the same problem. I again opened both .ini files in gedit and went line by line with them using a non-case sensitive find on "pdo". They were absolutely, completely identical. Finally, I gave up trying to understand the problem and just went for the easy fix. I removed the .ini from Apache2 and replaced it with the one from cli, and voila! I have PDO enabled in Apache2. I still have absolutely no idea what the problem was, but at least it's solved.

Trouble using MsSQL with PHP

I am debating between using MsSQL and SQLSrv to connect to SQL Server.
Our platform is running IIS7 on Windows and using PHP. We tried using the MsSQL extension to work but had problems so we decided to use SQLSrv instead since it was easier to get working.
Using MsSQL would be the preferred option because it fits the workflow better and the function names are similar to the ones used in SQL. Is it worth the effort to use MsSQL with PHP in light of the problems we are facing or should we use SQLSrv with the downsides mentioned.
Also, on the MSDN Docs for SQLSrv it mentions that the documentation is for preview and might change. Does that mean the functions could end up changing?
As far as the notice on the documentation all it means is they may change the wording of the document later in its release, I can't promise that the functions will stay the same however nothing on that page leads me to believe otherwise. Here is a Microsoft Wiki article on Accessing SQL Server Databases from PHP is says that the process outlined on that page is compatible with SQL Server 2005, SQL Server 2008, and SQL Server 2008 R2 so the software should not change since it needs to maintain compatibility with older versions of SQL Server.
You may also want to reference that wiki article, it contains step by step setup procedures for MsSQL and SQLSrv which may work for you and fix the issue you have.

How easy is it to use PHP on an MS Server with MS SQL?

I generally use linux servers and program in PHP (plus other associated technologies) with mysql databases. A client has existing ASP sites using MSSQL databases on a Windows server and wants some new sites created on their server using their MSSQL database as the main data source. I have used ASP in the past but much prefer PHP so would rather use this.
I just wanted to confirm that i'm right in saying as long as the server has PHP installed (which it does) then there's no reason I can't create a PHP site on the Windows server and just use different connectors to connect to the MSSQL db (rather than what i would usually use for connecting to a MYSQL db). Presumably (other than the different connect/query code) this would work in pretty much the same way as with a linux setup with mysql and i could then code the site in PHP but use their existing datasource?
I would be extremely grateful if anyone could confirm i'm right in saying this and if there's any other issues that might cause any problems?
Thanks so much for your help as ever,
Dave
You can enable MSSQL support in PHP on Windows. The default Windows PHP install has the php_mssql.dll extension commented out in the php.ini file. Uncomment that line, restart Apache, and it should work.
There is a supporting DLL called ntwdblib.dll that you may need to find a replacement for, as the version included with PHP may be outdated and won't work with newer versions of SQL Server. (I had this problem when setting it up.)
There are two different libraries to connect to SQL Server from PHP:
The legacy mssql extension, which has been discontinued on Windows
Microsoft's sqlsrv extension, which only works on Windows
I've basically worked with the second one and I can say it's a very interesting product. It's robust, it has a very nice interface and it's totally up-to-date. But what I like most is that it has very nice features. E.g.:
It can return dates as PHP DateTime objects
It provides a PDO driver
The only drawback of using SQL Server is that there isn't an easy way to write a cross-platform app but I understand it isn't problem in your case.
Yes, it is rather straight forweard.
You need to have the mssql library activated in php.ini. Which can be troublesom.
MSSSQL docmentation

How to migrate from my WAMP environment to using MSSQL?

I have on my local PC installed WAMP environment (using WampServer OS).
Now I would need to change one script from working with MySQL to MSSQL.
I have no idea at all how to proceed, where to download MSSQL, how to install it and how to connect with PHP?
Thank you very much
Download mssql express http://www.microsoft.com/Sqlserver/2005/en/us/express.aspx
Familiarize yourself with one of the great database abstraction layers, for example PDO http://www.php.net/pdo
Refactor your code to use the database abstraction layer
You may need to rewrite the mysql specific things to "standard" SQL
Start by getting Sql Server working. If you are using an old copy of Sql Server (pre 2005) you will need to make sure ntwdblib.dll is present in your System32 directory, and removed from your PHP dll directory (ntwdblib.dll is installed with the enterprise tools, so you may have to install them on your PHP box as well). Once you have Mssql querying properly, start finding where Mssql differs from MySql in your code.
A couple of tips:
The ntwdblib doesn't accept long strings (I think it is limited to 4k, but don't quote me on that). You have to use Stored Procs if you are trying to process a string longer than 4k.
Try to use Sql Server 2005 if you can (see above), the ntwdblib.dll is ancient and has numerous issues.
The PHP site is your friend for mssql.

Categories