Archive for the ‘Web Things’ Category

XAMPP and the PHP CLI

Sunday, July 27th, 2008

Like a lot of people I do most of my development work on windows PC and locally run a web a server and database. Like a a lot of people I just downloaded and installed a server bundle. For the last few years I have used Apache2triad and it has generally been pretty painless, but I’ve recently been forced to abandon it. Unfortunately the development seems to have been abandoned about 2 years ago.

The reason I abandoned Apache2triad was PHP versions - I wanted to do some work with Google Base using the Zend Google Data Library which required PHP 5.1.4+.

Looking around at the various bundles I decided to go with XAMPP - a lot of people seem to use it and it seems to get pretty good feedback. I won’t say the process was entirely painless (it took a couple of goes to get everything up and running) but eventually it all seemed OK.

The fun started when I decided to do a bit of baking (generating scaffolding code for my CakePHP app from a command line interface). Nothing worked.

Looking into it I discovered more than I wanted to know about the PHP Command Line Interface (CLI) which I had happily used for years with no idea it actually existed, having assumed it was just there as part of PHP.

After a lot googleing and a lot of trial and error I got it all working again and this is how I did it.

My environment is Windows XP Pro Service Pack 2 with XAMPP installed on E:/

  1. Downloaded the latest version of PHP and replaced the entire contents of E:\xampp\php\.
  2. Added to the E:\xampp\php to my environment PATH.

At this stage PHP CLI wwas now working but there were nasty errors e.g. I was uanble to connect to MySQL from scripts. I discovered that this is because PHP CLI uses a different php.ini file to regular PHP.

To fix this I copied my php.ini from E:\xampp\apache\bin\php.ini (the default XAMPP ini file) to E:\xampp\php.

I then checked the PHP CLI again using php -v at a command prompt. There were now about 6 errors displayed, concerned with modules that could not be loaded or found. I believe that these concern modules just that aren’t meaningful in CLI mode. So I went through my new php.ini in E:\xampp\php and commented out the directives that were causing the errors until PHP CLI ran without errors.

Finding overlapping dates and times in MySQL

Thursday, May 1st, 2008

Quite often you end up in situations where you are required to check and see if one time period overlaps another time period. Probably the most common situation this occurs in is when you are building a booking system - be it for tables or cars or rooms.

You have a series of entries in a database with a start (date)time and an end (date)time and before adding a new record you need to check that it doesn’t overlap with another booking.

The solution is fairly simple but I always end up making a quick diagram on a piece of paper to check.

Time overlapping diagram

As you can see two time periods can either be sequential (i.e. there is no overlap at all) or they can overlap in one of four ways. Put this into a diagram and the solution becomes pretty obvious.

There is an overlap if end_time_1 > start_time_2 AND start_time_1 < end_time_2

Time start_1 start_2 end_1 end_2 end_1 > start_2 start_1 < end_2
1 09:00 08:00 11:00 10:00 true true
2 09:00 10:00 11:00 12:00 true true
3 09:00 08:00 11:00 12:00 true true
4 09:00 09:30 11:00 10:30 true true
5 09:00 07:00 11:00 08:00 false true
6 09:00 12:00 11:00 13:00 true false

An example SQL query would be something like the one below but make sure your datetime formats are correct - in MySQL the default format is YYYY-MM-DD hh:mm:ss

 
SELECT * FROM bookings WHERE room_id = '" . $room_id . "' AND ((date_end > '" . $start_date . "') AND (date_start < '" . $end_date . "')) ";

The above query will pull back the records where the times overlap.

blinks.org.uk

Thursday, April 17th, 2008

Lately I’ve have taken a little bit of time out from Art-Thing and have been working on a smaller side project called www.blinks.org.uk

I’ve been using this as a bit of a test bed for various aspects of Art-Thing but it is also a fun little project in its own right. AND even better it should be ready very soon, it is a directory of UK businesses and services with a pretty flat structure based on tagging and regions. Fast, easy to use and fun (if a business directory can be fun).

The site is almost ready to launch and the whole process from the first ideas until now has been very quick - it is built in CakePHP 1.2 and jQuery which make coding a pleasure again. It’s also fun to do a bit of design for a change instead of just the stuff under the hood.

Here is a sneak preview:

blinks.org.uk

If you own or manage a business in the UK why not sign up for FREE with blinks.org.uk and see how it can help your business.

blinks.org.uk is a brand new directory of businesses and services based in the UK.

Every entry in the directory is approved by a real person and businesses have to provide their actual address so the directory is completely spam free and only contains quality listings.

  • Link back to your website (great for SEO)
  • Add a description of your business or service
  • Add an image or company logo
  • Update your entry whenever you want
  • Add you business or service to multiple categories
  • Add tags (keywords) - that are right just for you
  • Automatically show your location on our map

Finding a business in the UK - made simple

MySQL import / export at the Command Line

Wednesday, March 19th, 2008

Like many (most?) developers when I work with a database I tend to manage them using another programme - usually either phpMyAdmin or Navicat. However there are times when you have to get basic again and dig down to the Command Line (usually because of an access issue like a firewall setting you can’t change or because you need to import a file too big for phpMyAdmin). The trouble is if you only use these commands once in a blue moon you soon forget them.

Dump (export your database)

  1. Login to the shell or Command Prompt, navigate to where you would like your file saved.

  2. mysqldump --user=your_username --password=your_password your_database > your_dump_file.sql

Where:
your_username is a mysql user with the correct rights to the database you want to dump.
your_password is the password for your_username.
your_database is the name of your database.
your_dump_file.sql is the name of the file that will be created in the export.

Import

  1. Create the database that you want to import into, but leave it empty or if you are using an existing database remove the tables (make sure you have a backup first).
  2. Login to the shell or Command Prompt

  3. mysql --user=your_username --password=your_password your_database < your_file_to_import.sql

A Theory of Project Costs

Monday, March 17th, 2008

Lately I’ve been giving a lot of though to the way costs for projects are estimated. It always seems a very hit and miss affair. One designer I used to work with used to work out the costs as accurately as he could and then double whatever number he came up with - this worked as well as anything - and fairly accurately reflected the time / cost of what he was doing.

I think a lot of the problem is to do with the way projects scale - a £10,000 project is not necessarily 10 x more complex than a £1000 project, but more importantly it is far easier to scope a static webpage with 10 pages and a contact form than website where the client guidance goes something along the lines of we want it to be a bit like Facebook {edit as applicable} but aimed at Pig Farmers {edit as applicable}.

The trouble with building complex applications is that it is often hard (if not impossible) to anticipate problems until you come across them. I suppose this has a lot to do with the rise Agile Development - using it as a way of getting away from specifications that often rapidly loose any relationship to the project they define.

Development is really an evolutionary affair and clients will change their minds in response to what they see - but God is (as they say) in the details - and it is often genuinely not possible to know how a project will go once it starts to take shape. Good project management I suppose the art of reconciling these evolutionary forces with budgets, clients and what is actually possible.

Right now in my current job I don’t really have any say in how projects are costed - and they are costed as well as anywhere else I have ever worked - which is to say as accurately as possible - but of course I have to work with budgets and liaise with clients over all the technical nitty-gritty - so I have lots of time to observe.

My current theory goes something along these lines (BTW all figures are just made up)

c = minimum cost
t = cost per database table
i = number of database tables

total cost = c + (t x i)

BUT this isn’t right yet there a number of additional factors that I am trying to work into the equation so far I have:

p = Client Knowledge - an overly knowledgeable client cause as much trouble as an IT somebody who is IT illiterate - ideally we need somebody who understands what you tell and has ideas of their own but can also understand advice.

z = a factor to fine tune t x i

For Example: if i = 10 then the total cost might work out as 1 x (t x i) but if i = 60 then total cost = 0.7 x (t x i)

I wonder what ever happened to my old graphics calculator…

To be continued…