Friday, 30 March 2007

PHP: Handling MySQL replication failure gracefully - Part 2

The first version of this code failed to work on 5.1 so here is a version that does:
if(DATABASE_REPLICATION_CHECK)
{
$result = mysql_query("show slave status;");
$row = mysql_fetch_assoc($result);
if( ($row['Slave_IO_Running']!='Yes') || ($row['Slave_SQL_Running']!='Yes') )
{
$fp = fopen('tmp/halt', 'w+');
fclose($fp);
header('Location: index.php');
}
}

Remember to add something like:
if(file_exists('tmp/halt')) exit('Unable to complete request at this time');

at the start of your app execution so as to stop users entering data that can cause all kinds of living nightmares when it comes to patching the data together.

Wednesday, 28 March 2007

Pivoting Data in MySQL

This is a good read for anyone who has ever tried to pivot data from a table in MySQL using client side code like PHP when you can with some careful query construction do it in MySQL.

Friday, 9 March 2007

All in the "swizzle"

Just incase I lose it.. and as some proof I was on the track with it.. this is the foundation of a new tree theory I am working on.


char *rotKeys(char *key)
{
int x,y;
char *ret = (char *)calloc(8, 1);

for(x=0;x<=7;x++,key++)
{
for(y=0;y<=7;y++)
{
ret[y]|=(!!(*key&(1<<y)))<<x;
}
}
return ret;
}