Oct 272010
 

As MySQL triggers are now available in the community edition I decided to sort a small but irritating problem (not sure how long but last time I checked they weren’t).

I needed all entries to a field to be stored in upper case.  Easy enough in PHP but there will be situations when entries will come from sources I have no control over, a trigger would be ideal, or so I thought:

Can’t update table ‘tbl’ in stored function/trigger because it is already used by statement which invoked this stored function/trigger

Fair enough, that message suggests that because I am already working on the table I cannot perform the task I want.  Probably the table is locked, but I want to update a field entry before it is updated, thus why can I not make the change before its locked.

Well I can’t.

MySql’s documentation had a problem today, a ‘recursive redirect’ so I could not find anything there to help.  I resorted to a dusty copy of ‘MySQL Database’ and discovered the NEW object contains all the field data and thus can be updated before saved to the table.  Here’s an example:

delimiter |
CREATE TRIGGER ucase_emails_code
BEFORE UPDATE ON emails
FOR EACH ROW
BEGIN
SET NEW.code = UCASE(NEW.code);
END;
|
Oct 262010
 

The following PHP code repairs databases that show an overhead. Remove the errorlog function if not required.

<?php
$sql = "SHOW TABLE STATUS";
$result = mysql_query($sql) or errorlog( __LINE__."\n\n".mysql_error()."\n\n$sql");
if($result && mysql_num_rows($result)) {
  while($row = mysql_fetch_assoc($result)) {
    if($row['Data_free'] > 0) {
      $sql = "REPAIR TABLE ".$row['Name'].";";
      $repair = mysql_query($sql) or errorlog( __LINE__."\n\n".mysql_error()."\n\n$sql");		
      if($repair) {
        echo "<br /><em>".$row['Name']." succesfully repaired</em>";
      } else {
        echo "<br /><strong>".$row['Name']." error: ".mysql_error()."</strong>";
      }
    }
  }	
}
 
//Stub
function errorlog($msg) { echo $msg; }
 
?>
Sep 012010
 

What’s changed at the BBC News site?  There must be something because I spend more time at Sky or the papers instead now.  On the rare occasions I do visit something about the site irritates me.

bbcpulse BBC Is Pulse Enabled? Whatever Next? Advertising?As I read an article today something kept distracting me, it happened so fast it was over before I could see the cause.  My head bobbing trying to find the cause must have been a site.

To find out what was happening I stopped reading the article and watched the refresh gauge on the bottom right of my browser.  After a few seconds there it was!  A brief flicker.  Not a full refresh, just the mere shade of an outline on the progress bar which suggested something was happening in the background.

bbc2 300x142 BBC Is Pulse Enabled? Whatever Next? Advertising?There was no ticker on this page so that could not be the cause.

I viewed the source and a few lines down spied an odd statement in an HTML comment “PULSE_ENABLED:yes”  WTF?

Are the BBC are trying to annoy me (as if the license fee squandered on pointless court cases isn’t enough)?

Sifting through copious amounts of JavaScript and duplicated dependencies and a bizarre selection of bloated common css errors leads to many more curious comments.bbc3 BBC Is Pulse Enabled? Whatever Next? Advertising?

It’s sad, I like their content and I suppose as I pay for it so I should be encouraged to use it but this “pulse” issue is probably the  reason I lost interest in it.

peculiar as I assume this problem is going to reek havoc with their stats, but then why should the BBC be monitoring stats?

 Posted by at 2:48 pm  Tagged with:
Aug 152010
 

whs 300x211 Are you happy with your backup strategy?As a software developer with hosting development and management experience its not unusual for me to be asked to help someone who has lost a file. There are three places a backup can sometimes be found:-

1. There is a proper backup strategy in place.
2. An adhoc backup may include a copy, to find these think outside the box, did you zip it up and email it to someone?
3. A deleted file can be restored or pieced together from file cache or fragments not yet overwritten.

I am surprised at the number of hosts that do not perform backups. Some will offer extra disk space so you can do it yourself for a fee, some will handle backups for you for a fee, but few do it automatically. The rule has to be If you do not maintain backups then its unlikely anyone else will.

Relying on your programmers has some merit but you should not rely on it. Programmers don’t like to write their code twice and so we find a way to automate the process to ensure we have the best possible solution.

The best backup strategy
Any backup strategy is better than none but if you want an easy to use and cost effective solution to backup several PCs/Macs/Mobiles as well as your hosted applications then check out Microsofts Home Server. It requires a separate PC to operate but nothing special. This is one of those applications you hear little about. It’s not expensive and is really good at what it claims to do (see this link for the sales pitch).

Expanding the amount of disk space available is as simple as plugging in a new external USB drive. So you can dig out those discarded drives and use them as additional space. Home server not only keeps a backup but you can use it to store important items such as photos and videos and it will make duplicate copies, so if a hard disk fails all you need to do is throw in another and it will take care of duplicating the files again for you.

Access to TV, music and all you media is available 24/7. Connect it to your wirelss router and the process of sharing your media around the house really does become straightforward.

Backup for business
I have a few offsite Linux servers, some more than 4,000 miles away. Home server backs these up every day and retains as many versions of those files as you think is convenient. By default you can recover any file up to 3 months old but I have extended this to 12.

Jul 132010
 

wiki’s make it easy to edit through the browser. I like everything about them except for two irritating problems.

  • They all look the same
  • They are not easy to customise

Both problems now solved by wikkawiki.

It remains a wiki without the extensive features of the growing groupware solutions such as tikiwiki which are amazing feats of engineering, but only serve to complicate something that is supposed to be easy.

wikkawiki produces excellent documentation, fast.  Setup accounts for your editors then disable login and you remain in control of who gets to edit.

Styling the wiki can be done through CSS plus a header.php and footer.php file. Click here for an example of one with a modified design.

It includes Geshi by default (for colourised code snippets) and you can wirte PHP directly into a page and it will be evaluated at read time.

see http://wikkawiki.org/HomePage for more details.

Jun 302010
 

mypph 300x228 Using twitter as an alerting platformI received an email from Clickatell inviting me to top up my SMS account.  After a split second consideration I realised I did not need them anymore.  Sorry Clickatell!

Twitter is more convenient.  I have set up a few private accounts and subscribed to them through my own.  When an event occurs I receive notification direct to my phone as a free SMS message direct from twitter.

Although twitter has been unreliable lately it has proven more convenient than using Clickatell.  In time twitter will fix the problems and they may even be suitable for mission critical solutions.  I hope so because they are easy to use and should spawn many superb product ideas all designed to keep us informed with the information we want now, not just when we visit facebook.




Jun 212010
 

homepage 150x150 Payment Processing for OnelogbookOnelogbook is an outdoor sports activity program currently in development. My task was to add Paypal payment processing to the joining form.

Technologies used were PHP, MySQL, Javascript and I created a few minor graphics. Payment information is sent to Paypal for processing. On successful payment Paypal return IPN (Instant Payment Notification) code to the website and the user is authorised to use the website extended features.

Javascript is used for form validation and PHP provides the server side code. If a payment is cancelled user details are removed from memory and the database is not updated (you can see the cancellation notice at the end of this short high speed video).

And a “Please Wait” graphic – scourge of Paypal Payment Processing!

pleasewait Payment Processing for Onelogbook

Jun 192010
 

Styleroomz asked for a widget to showcase products. Data is retrieved from their affiliate source as XML in a zip file.

The XML is updated daily to ensure prices and special offers are fresh.

The widget uses HTML, XML, MySQL, Javascript and PHP. Data sources include XML for the affiliate information such as coded links, pictures, pricing and store information, and MySQL used by the Styleroomz ecommerce software to link to their pages. The Yui library from Yahoo was used to create the carousel effect.

The following short video demonstrates how the widget in use.