Adding mssql capability to PHP5 on CentOS

I had a need to connect to MSSQL using PHP version 5 from a CentOS 5 server. To do this I needed FreeTDS and the module mssql in PHP. After a diligent search I found that there was no quick and easy way to install the mssql module, like “up2date install php-gd” to get GD to work from PHP.

I found a few places that had ideas and hints to make this work, but finally used the directions I found at http://www.howtoforge.com/installing_php_mssql_centos5.0 (slightly altered to fit my means) and will duplicate here so I can easily find it later.

At first I thought I needed to recompile PHP, but as it turned out I only needed to pre-compile it so that I could fetch the mssql.so, and then manually edit the php.ini to use it.

Continue reading Adding mssql capability to PHP5 on CentOS

Using JOIN within the Zend Framework

I found documentation very sparse on the subject of using JOIN with the Zend Framework. So i set out on a quest of many hours figuring out how to get it to work. Here is what I ended up with.

I do not claim that this is the best way to do it, or that it is correct, but here is how I solved this and got JOIN working within Zend Framework.

Continue reading Using JOIN within the Zend Framework

Apache parse PHP from within files using ‘.html’ extension

Recently I had someone that needed to move their site to a new server. The site was entirely created with the files using the .html extension, but had embeded inside.

I simply cleared this up by adding the following line to the httpd.conf, and after a reboot of Apache i was set to go.

AddType application/x-httpd-php .html

If you were to need this type of action for files using the .htm extension you would do the same thing, but replace the .html to .htm in the line.

Script memory usage, and displaying with PHP

I recently had a problem where a script written by someone else was stopping. There was not warning, error, or indication at all what the problem was. The script simply died as if the process ended.
After a bit of troubleshooting I found that the script was ending due to memory loss. So here is how I used PHP’s memory_get_usage() to troubleshoot through it.

Here is a chart I used for conversion, to simply display the numbers.

1 Byte = 8 Bit
1 Kilobyte = 1024 Bytes
1 Megabyte = 1048576 Bytes
1 Gigabyte = 1073741824 Bytes

Here is how I used echo to display the memory used in MB’s at different points in the script to troubleshoot.

echo "Memory Usage: " . (memory_get_usage()/1048576) . " MB \n";

Getting differences between dates quickly in PHP or MySQL

I recently needed a way to figure out the difference, in days, between two dates. Here is how I did it.

Using PHP:

$expireDate = "2006-02-07";
 
$year = substr($expireDate, 0, 4);
$month = substr($expireDate, 5, 2);
$day = substr($expireDate, 8, 2);
 
$splitExpireDate = (mktime(0, 0, 0, $month, $day, $year));
$today = (mktime(0, 0, 0, date("m"), date("d"), date("Y")));
 
$difference = (($today) - ($splitExpireDate));
$convertToDays = ($difference/86400);
 
echo $convertToDays;

Using MySQL:

SELECT (TO_DAYS(expire_date) - TO_DAYS(CURDATE())) AS days_expired FROM tablename;