PHP with MSSQL on Mac OS X Snow Leopard

I’ve recently needed to connect to an MS SQL database remotely from my Mac OS X development environment. I like to use the default PHP installation provided to me by Apple, as such I unsurprisingly found that the standard installation is missing the functions needed such as mssql_connect(). You will have this problem by default in OS X and it the response when you try to use and function prefixed by mssql will be:

Fatal error: Call to undefined function mssql_connect()

I began my quest to install the necessary packages a few hours ago and thought I would document the process here as I didn’t find anything specific to my needs.

My environment is a pretty vanilla Snow Leopard (10.6.5) PHP environment, using a standard PHP runtume and the Apache server provided by Apple, so no MAMP or Entropy PHP here. I found a great guide here designed for use with MAMP that I learned from to get it working for me.

First off I started by obtaining the latest stable source release of FreeTDS, you can get this by clicking here.

Once downloaded, expand the archive and visit the folder.

cd freetds-0.82
./configure --prefix=/private/etc/freetds --with-tdsver=8.0 --sysconfdir=/private/etc/freetds/conf
make
make install

Next you need to acquire the latest source release of PHP. Now I’ve only tested this with one release so you may need one that matches you installed version. For me I was running PHP 5.3.3 and it worked fine when I downloaded the 5.3.4 source code. Anyway you can obtain the source from here, download and expand as before.

Now this is where I stopped following the instructions from Scott and began playing around. In the terminal:

1
2
3
4
5
6
7
8
9
cd php-5.3.4
./configure --with-php-config=/usr/bin/php-config
make
cd ext/mssql/
/usr/bin/phpize
./configure --with-php-config=/usr/bin/php-config --with-mssql=/private/etc/freetds
make
cd modules/
sudo cp mssql.so /usr/lib/php/extensions/no-debug-non-zts-20090626/

What is different with the above is that I am forcing the use of the pre existing PHP installation to configure the compilation of the new MS SQL extension. Before I did this I was getting an error in the apache error log:


PHP Warning: PHP Startup: mssql: Unable to initialize module
Module compiled with module API=20060613
PHP compiled with module API=20090626
These options need to match
in Unknown on line 0

After completing the above compilation of the module, open your PHP.ini file, by default on OS X it will be located at /etc/php.ini. Open this file in your preferred editor and add the line ‘extension=mssql.so’.

After doing this restart your apache server by running ‘sudo apachectl restart’ and then create a phpinfo() page where you should see a new section that looks something like:

I hope this helps someone, if nobody else reads this I can claim it was for my own reference :) .

Posted in PHP Tips, Uncategorized | 6 Comments

My Portfolio Plus for WordPress

About the Plugin

My Portfolio Plus is a plugin designed for WordPress 3.x that enables a Web Developer/Designer to create a portfolio for their work in a very easy way that doesn’t rely on outdated methods such as custom fields and proprietary editors.

Extraordinarily Simple Management

Using the latest technologies offered by the newest version of WordPress, you can add a Project as you would normally add a Post or Page. The Project Edit Page is especially easy to use, as you give the Project a title as you would a standard WordPress Post along with some content to describe the work undertaken.

What is unique about this plugin is that included in the editor is a series of fields to collect information regarding that project. Currently the plugin collects the URL of the site, the Client Name and the Date the project was completed.

Admin Interface

Below are some screen shots to showcase the familiarity of the user interface to existing WordPress users.

Automatic Thumbnails

Some say a picture is worth 1,000 words and this plugin helps you say those words with no extra effort. Using the power of Shrink The Web (Free Account Needed)  and the URL of the site that you have already entered, My Portfolio Plus will automatically retrieve a generated thumbnail of the site in question and by default will be displayed on the Projects listing page for all to see.

Live Site Preview

Thumbnails are great but your hard work deserves to be seen as it was intended at full size. That is why by utilising the power of colorbox, My Portfolio Plus enables the end user to click a site thumbnail and view it within a gorgeous in-place frame without ever leaving your portfolio page.

Filter by Platform

Using the powerful new taxonomy features of WordPress 3, I have added the ability to group projects by the platform used to develop them. For instance you could define that a project was completed using PHP, WordPress & jQuery, another using .NET & Moo Tools and finally a site using PHP, Zend Framework & Scriptaculous.

While this may seem pedantic at first, the default project list template included with the plugin comes complete with a sidebar that will list all of the platforms you have defined, in the form of a tag cloud. Clicking on one of these platforms will filter the projects list to show only the projects completed using that platform, this information is available through a URL too. You can link to all of your completed WordPress projects by simply sending the link: http://your-site-url/projects/platform/wordpress/ to a potential client.

Speed Up Your Portfolio Management

Remember, this is all available by simply providing the Name of a Website you have worked on and the URL at which it is available. Depending on the size of your project description you can add a completely new project in under 30 seconds.

Say Thanks

I wrote this plugin to power my own portfolio and thought I would contribute back to the wonderful WordPress development community. If however you like the plugin and wish to make a donation to show appreciation for my work then you can do so by using the following button:



Getting Started

How to Download

You can obtain the plugin from the official WordPress Plugin site, or by searching for the plugin from within the WordPress Admin area.
Download Here

Installation

  1. Unzip the plugin archive
  2. Upload the entire folder MyPortfolioPlus to your plugins folder (/wp-content/plugins/)
  3. Ensure your wordpress uploads directory exists and is writable (/wp-content/uploads/)
  4. Activate the plugin through the ‘Plugins’ menu in WordPress
  5. A new Projects Admin Menu should appear below Comments
  6. Go to Projects -> Options to configure your preferences
  7. If you want to utilise Shrink the Web thumbnails, you must enter your API credentials on this page.
  8. Add a Link to http://your-site-url/projects in the main site navigation

Requirements

  • Only PHP 5+ is supported
  • PHP Safe Mode is not supported
  • WordPress 3.x + only

Customising the Layout

How-To

To make installation as easy as possible, I included a default set of templates based on the default WordPress 3.0 Twenty Ten theme. These however will not work (well) with every theme on the market and so I have included the ability to override these files. To achieve this you simply need to copy any one of the three view files from the MyPortfolioPlus/views folder and place it in a new directory located within your chosen theme, named ‘portfolio’. When rendering the page, the plugin will first check for the existence of a template file in the user them, before falling back on the plugin defaults.

Example

If you wished to change the layout of the Single Project template, you first need to copy the file /wp-content/plugins/MyPortfolioPlus/views/single-project.php to /wp-content/themes/your-theme/portfolio/single-project.php. You can then make any changes you wish to this layout without worrying about future updates to the plugin overriding your changes. Repeat this process for each of the views you wish to customise.

Available Information

To begin with only a few fields are available to describe each project, I am activley looking to expand this list and if you have any suggestions then please leave a comment. The current available variables are:

  • $project->getURL()
  • $project->getClient()
  • $project->getDate()
  • $project->getImage()
Posted in Plugin, Wordpress | 81 Comments