March 12th, 2009 | Tags: ,

Update: This article is considered outdated, and is only valid for PHP versions before 5.3. I’ve started an IIS Tutorial Series on Talking to SQL Server with PHP on IIS, which is valid for any versions of PHP 5.2.4 and later.

I have been pulling my hair trying for many hours to connect to a MSSQL server remotely with PHP.  I was able to connect using ODBC but I wanted a more elegant and native solution.  Trying to connect using PHP’s MSSQL database library constantly gave me the error:

Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: 172.xxx.xxx.xxx

I’ve tried using the computer name and several other solutions.  Upon doing a lot of research and reading the user notes on the PHP website, and trying out several solutions before finding out a working solution.  I’ve found that the file ntwdblib.dll packaged with PHP5 (currently 5.2.9-1) is an old version (2000.2.8.0).  Most people suggested replacing it with the later version, 2000.80.194.0.

Click here to download this version of the file: ntwdblib.dll

I’ve replaced the file and restarted my IIS webserver and the connection was successful!  I hope this helps for those searching for the solution.

March 3rd, 2009 | Tags: , , , ,

For the last year to two I’ve familiarized myself quite a bit with AJAX and was able to leverage its power in providing a seamless user experience with so-called Web 2.0 style of web development and design.  I’ve began AJAX with simple XMLHttpRequest (XHR) to request HTTP data from the server.  Then, I’ve stepped up my game and utilized the jQuery Javascript Library to do AJAX.  One of the best things I loved was the ability to handle a JSON data type request from the server.  Unlike a block of XML or HTML, JSON is so flexible as one is able to return many different types of information such as a status code, status message, and any data along with a HTTP Status Code 200 (OK).  I’ve pretty much defaulted to using JSON as the response type for all my AJAX called through jQuery.

At work, while working with a third-party application for generating personalized websites, the lack of information the system provided, I’ve tried using AJAX to request information from another server that can request for more information.  Upon discovering that AJAX cannot perform cross-domain requests (Same Origin Policy) due to various security issues that would arise, I’ve found something called JSONP.  Although it’s technically not AJAX (it doesn’t use the XMLHttpRequest object), it was a workable hack-ish workaround the limitations of the current state of AJAX techniques using a GET request that returns a JSON object wrapped in a Javascript callback function.

Today, I’ve discovered a proposal by Douglas Crockford for a JSONRequest service that allows cross-domain requests with requests and responses in the form of JSON, minus some of the issues that plagued XMLHttpRequest if it was usable cross-domain.  The big one would be that cookies or HTTP Authentication data would not be sent along with the request, so that prevents Cross-Site Request Forgery.  Though the proposal has been created nearly three years ago I’m surprised that it hasn’t been implemented in any browsers yet.  I hope a future version of Firefox or some browser would implement it and slowly spread its implementation.

February 26th, 2009 | Tags: , ,

I was reading this article about how when many Japanese Internet users want to visit a website, they type in the name of the website on Yahoo! Japan to do a search and click on the result rather than directly typing the domain name into their web browser’s address bar.  (This is based on Yahoo! Japan’s 2008 search ranking that the top keywords are to specific websites.)  This made me think about how I used to enter information into the address bar and how I do it now.

Since years ago when I was an Internet Explorer 6 user I would always have Yahoo as my home page.  In fact, I still do now since it does provide interesting news.  Whenever I would go to any specific website, I would type it in as a search term in Yahoo.  The reason I did this was because anything I typed directly into the address bar would stay in the drop-down list.  Why this bothered me was because I used the address bar as like a “super-favorites” menu of the top 10 or so websites I habitually visit everyday.  You know, like webmail, favorite forums, etc.  Yes, I know that’s not how you use it, but it was easier than digging through a long list of bookmarked favorites, and also I wasn’t a fan of the ‘Links’ toolbar either since it took up screen real estate. Since the address bar menu only displays the entries by most recently visited, by typing some other random website into that address bar pollutes the list with that address, and there was no easy way to delete that entry except to clear the whole browser’s history.

Then came the days when I switched to Firefox 2.  I was still following the same habits of doing a keyword search to get to a website.  However, Firefox 2 did have a method to remove entries, but it was cumbersome to often delete these entries.

Then came Firefox 3, with its heaven-sent “Awesome Bar,” as they call their address bar.  This made my search-to-get-to-a-website illness disappear.  The Awesome Bar literally, out of the package, displays your most visited websites, which, not surprisingly, are the websites I visit everyday!  Firefox keeps tabs on the count of how often you visit each website.  Since the Awesome Bar sorts by hits, I could free myself by typing any ol’ web address I’ve visited one or two times directly into the address bar and still not pollute what shows up in the address bar.  The Awesome Bar also searches your history urls and page titles with whatever you typed so that’s very helpful.  There are times where I’ve visited a website but had not bookmarked, and the history auto-search makes forgotten websites so easy to find.  Thank you Awesome Bar!

February 24th, 2009 | Tags: , ,

I was just reading this blog entry and it reminds me of why using a framework gives the developer so much more flexibility and better off long term, especially for business information systems where business rules change will be made.  Although comparing using a framework as opposed to an out-of-the-box solution is fairly subjective, I do believe that using a CMS does have its advantage when budget is tight.  However, as a full-time web developer for a company, like myself, using a framework is definitely the way to go.

One framework I’ve began using recently is the Kohana PHP 5 Framework.  It’s a very lightweight framework using the Model-View-Controller (MVC) pattern.  While working with the framework, I’ve found several things that I really liked over several CMS software such as Joomla! and Drupal could not provide (or not that I’ve noticed, at least).  I really like Kohana’s simple ability to allow all your scripts to sit under the public root, and be the core of several applications.

Security-wise, I like how simply it is to keep everything under the public root.  The only thing that sits on the public root is in index.php file and any client files (images, CSS, Javascript, etc.)  If the PHP parser fails and the PHP code is exposed, only the index.php is exposed to the public, and it doesn’t contain anything critical except relative paths to your main application directory, which is inaccessable publically.  Kohana has a core “system” directory, and one more or “application” directories for each of your web application.  With this type of filesystem, they’ve implemented the so-called “cascading filesystem.”  If there is anything not set in your application directory (e.g. configurations, error pages), Kohana automatically aquires those lower in the filesystem chain, with the “system” directory being at the very bottom.

Kohana provides all the abstraction libraries for common use functions, like database access, session management, caching, etc.  Additional modules also such as the Auth module for user authentication makes it simple to create and manage secure passwords and sessions.  Even without a URL rewrite module on your web server, building SEO-link friendly apps should not be an issue.

PHP itself is a very lax scripting language that lets developers do whatever they want, which can have major disadvantages when trying to create organized apps.  Having a framework like Kohana definitely helps keep many things organized.

February 19th, 2009 | Tags: , , , ,

When working on a couple of e-commerce web projects at work, I’ve found that being able to generate a report dynamically definitely wows a client.  Over time, I was able to find and try out a several PHP libraries from creating reports such as MS Excel files, PDFs and fancy charts.  Here I’ve compiled a list of some of the most reliable, and best of all, free, libraries I’ve found for PHP.

Create MS Excel Files

PEAR’s Spreadsheet_Excel_Writer: This library has been pretty much untouched, and maybe discontinued, since the end of 2006, and although there have been projects forked from Spreadsheet_Excel_Writer, I’ve still found this original to be the most reliable.  It does pretty much everything you’ll probably need it for.  I haven’t tried any real advanced Excel features, but for most things like using formulas, type and style formatting, etc., it’s enough.  It is a part of the PEAR framework, so you’ll need to have that install.  The only issue is that there are some issues with outputting Unicode strings.  There are patches that people have posted around the Internet that fixes it and lets you set a UTF-8 encoding properly.  I’ve used it and it works, but I do not remember the original source of the patch.

Create PDFs

TCPDF: This is probably the best free PDF generation library I’ve found on the Internet.  I’ve came upon it by accident while playing around with Joomla! CMS coding, and I was wow-ed by the number of features that this library supports.  I’ve found that several other popular CMS also use it for their PDF generation purposes.  One of the most interesting feature is the ability to create PDFs from HTML markup.  Although I haven’t personally tested how good the HTML to PDF rendering is, it does support inline CSS.  It also has ability to create some charts and support for CMYK colors, which might be useful for those in the printing industry.  Unicode text is fully supported also, but will increase output file size because of the large embedded font data.  The great thing is that this library is constantly updated.

FPDF: The FPDF library is a fairly simple library and not as extensive as TCPDF, but it has enough features to create a nice PDF document.

FPDI: Technically not a PDF generation library, it’s main use it to be able to import an existing PDF as a template for you to work with.  The library supports both TCPDF and FPDF.  Very useful if want to create a variable-data template where text can be dynamically added on top of a PDF template on demand.  I’m sure with enough work you can create your own web-to-print system with these tools, but there are better tools for that (but not free), such as PDFLib

Create Charts

FusionCharts Free: A free charting software with tons of possibilities in the types of graphs you can create.  The charts are Flash, but you don’t need to know Flash, and use any common programming language (not limited to PHP).  The documentation is very extensive and you can be on your way to generating fancy charts with animation in no time.

PHP/SWF Charts: Another Flash charting software with a lot of graph types.  However, there is a paid license for it and accesses additional features and removes one of the most irritating feature of the free chart: when you click on a chart it goes to the PHP/SWF Charts website.  (There are workarounds to preventing that though.)

With these sets of libraries you should be able to generate some pretty slick and professional reports on your commerce website without spending a dime on software!

Now if I can only find a free library that can create MS Word documents…

February 18th, 2009 | Tags: , , ,

My Nintendo DS Lite has been collecting dust for over a year, and I’ve finally purchased an R4DS at IShopVideoGame.com hoping to make more use out of it.  If you didn’t know, an R4DS is a flash cartridge for your Nintendo DS that allows you to play ROMs downloaded from the Internet (yes… that’s not legal).  The whole flash cartridge business is quite shady in itself with lots of fake fakes (I say fake fake as there’s really no official one since Nintendo obviously would not support something like this), so it might be wise to do some research on which website to purchase it from, as there are a lot of potential scam websites out there as the products are created and shipped from Hong Kong or China.  I’ve received my from IShopVideoGame.com (from HK) in a week and can say they’re legitimate.

Getting the R4 to work requires a Micro SD card.  The regular R4 supports Micro SD cards up to 2GB, whereas the R4DS SDHC supports higher standards with higher capacity Micro SD cards (I purchased this one).  I’ve began playing Osu! Tatakae! Ouendan (押忍!闘え!応援団), a Japanese musical game, similar to the genre of Dance Dance Revolution of playing the game to the beat of music.

The R4DS is quite an amazing little device to get more out of your DS.  There are also homebrewed applications out there to add more life into your DS.  Though I suggest that if you use the R4DS, you probably should not use it to connect to the Internet, for example, through a game, as I’ve heard that Nintendo put something in that checks that your game is legitimate, and if not, may erase your saved data or possibly brick your DS.

February 18th, 2009 | Tags: ,

Welcome to my weblog! It’s been a while since I’ve written anything blog-like, and with the recent release of WordPress 2.7 and eventually having to incorporate it’s use on a work project, I’d thought I’d give it a try again.  Again, meaning I’ve tried it before and I got too lazy to update it.  Jimmy Li is my alias I go by for web development testing, and eventually what a few of my co-workers began to call me (mostly the evil side of me).

I will try to write mostly about various things and thoughts going on at the moment. Most of them will probably be in the technology sector, but I don’t want to limit myself to only that and also try to write about other things I do and places I’ve visited.

Currently, the website is fairly empty without a proper About page, and the blog template I’m using was designed by someone else, but over time I hope to learn more about the internal workings of WordPress and attempt to design a template of my own and figure out how plug-ins work.