PHP: Connect to SQL Server Database on Linux (and Mac OS X)

Microsoft SQL Server
Microsoft SQL Server

I have used PHP to connect to SQL Server plenty of time, and every time I would use the SQLSRV extension. The problem with that is, PHP’s SQLSRV extension is only available for Windows servers. Which wasn’t a problem for me because I would normally develop PHP on Windows machines. It wasn’t until recently I needed SQL Server access on a Linux machine.

It wasn’t as straightforward as I had hoped, and it certainly did not help to learn that the MSSQL PHP extension was removed in version 7.0, which took me a few hours to discover. I am writing this post in hopes that I save some people a few hours of pain, including my future self.
Continue reading “PHP: Connect to SQL Server Database on Linux (and Mac OS X)”

Installing Microsoft SQL Server Data Tools – Business Intelligence for Visual Studio 2013: Rule “Same architecture installation” failed??

So I had to install Microsoft SQL Server Data Tools – Business Intelligence for Visual Studio 2013 today, and was greeted with the above error. Based on the error, I assumed I had SQL Server 2014 x64 installed and I somehow needed SSDT for x64 and not x86. Funnily enough, the installation page suggests both x64 and x86 architectures are supported. I was frantically searching for a x64 installation.

Thanks to a StackOverflow post:

As the others have said, there is only a 32 bit version.

The important thing is, if you’re running an x64-based SQL instance (64-bit), make sure to select “New Instance” on the Installation Type page, and NOT “Add features to an existing instance”. Not doing so will cause it to error out.

I was selecting “Add features to an existing instance” thinking “New Instance” meant installing a new SQL Server fresh again, like most people would.

SQL Server: Taking Advantage of Transactions

I won’t go in depth about SQL Server transactions, but rather what you can do to apply destructive changes safely, like deleting records or updating them. It’s highly advised that direct queries don’t get run on production databases but there are situations where that is required.

Continue reading “SQL Server: Taking Advantage of Transactions”

PHP: sqlsrv problems with UTF-8 values? Set your CharacterSet option!

Are you banging your head trying to figure out how to convert a seemingly invalid UTF-8 value into a valid one? You might be surprised to know that the problem isn’t how PHP interprets the characters, but rather a database connection issue. If the UTF-8 value in question looks valid in the database but does not look right when displayed on a web page, that could mean your database connection settings are not set correctly.
Continue reading “PHP: sqlsrv problems with UTF-8 values? Set your CharacterSet option!”

PHP: Importing an SQL file via PHP script

Trying to import an SQL file using PHP? Most people will tell you that using PHP function shell_exec to run the MySQL client is your best bet, but what if you simply can’t do it that way? The solution is quite simple, actually, and doesn’t require programming skills beyond the basic file parsing and query executing.
Continue reading “PHP: Importing an SQL file via PHP script”