Tech Musings

Tuesday, April 24, 2007

ALTER TABLE syntax

Once and a while I'll need to INDEX a field (or fields) in one of my MySQL tables that are of the BLOB/TEXT (mediumtext) type. To do this, you need to use the ALTER table query with a length specified. I usually forget the exact syntax to do this so I decided to post it here:

ALTER TABLE `table_name` ADD INDEX (`text_field`(1000));


If you're like me and you forget to add the character length, you'll probably receive a #1170 SQL-query error that reads something like:

#1170 - BLOB/TEXT column 'text_field' used in key specification without a key length


which might occur if you try to alter the table in the future using phpMyAdmin.



After running the alter table command above do a quick repair operation of the table to rebuild the indexes:

mysql> REPAIR TABLE tbl_name QUICK;

Friday, April 13, 2007

PHP 5 Entropy Build

This one has gotten me more than once so I thought it best to log it here for future reference. If using the Entropy (www.entropy.ch) build of PHP 5 for Mac OS X, the php.ini file changes locations. I like to set the display_errors = On if I'm running PHP on my test box (recommend turning to Off in production environment) and sometimes will set register_global=Off from Off to On temporarily to test certain applications. Undoubtedly, I will make these adjustments in the old php.ini file and wonder why they're not working like I expect them to, then after an hour of head scratching remember that entropy uses its own php.ini in the new location. For the record, I've heard you can also manage register globals through .htaccess and virtual site config files, too. It's a security risk to have your register globals on and best to rewrite your code using superglobal array variables instead of taking the easy way out and making the change in the php.ini file. Am I right?!??? ;-)

If your php.ini file was located here /private/etc/php.ini

it switches to this location:

/usr/local/php5/lib/php.ini