This is one of those things I can never remember how to do when I need to do it. I don’t know why, it’s really quite simple:

SELECT emailaddress, firstname, lastname,
COUNT(emailaddress)
FROM customers
GROUP BY emailaddress
HAVING COUNT(emailaddress) > 1

Chocs To Go The goal for students on the intermediate PHP and MySQL course that I’m running for IWA/HWG is to create a working shopping cart. The course starts in only three days, and I decided I’d better walk the walk and prove I could do it. So I have quickly mocked up a working version of the cart they are expected to build and put it online here. I think it will be helpful to students to see what they are aiming at, and it will make it easier for them to work out the logic if they can click through a real example. The design may not win any prizes, but the basics are all there.

All course materials now written and double-checked, quiz questions written and checked, SQL scripts generated and tested … just need to put week one’s materials up now!

Why doesn’t SQL Server come with a built-in method for generating SQL dump files so you can easily port your data to another database? Microsoft in its own little walled garden I suppose; while the facilities in Enterprise Manager for exporting to Excel, Access, ODBC, CSV etc. can be very useful, sometimes you just need a bunch of SQL statements <whisper>so you can export your data to Oracle</whisper>.

SQLDumper to the rescue; a handy little free utility that does just that, with a neat user interface that lets you select which database/tables you want to dump. Windows only, but hey, it’s a SQL server tool after all! Downside: you have to download and install the .NET framework if you don’t already have it, but the setup program handles that itself — just something to be aware of if you have a slow connection.

Since 1999 I’ve been teaching online for the Open University. It may not pay brilliantly, but it’s regular income and I really enjoy doing it; OU students often overcome major barriers to achieve a qualification they missed out on earlier in life, for whatever reason, so they can be very rewarding to teach. And the fact that it’s online means I can conveniently fit it around other work. Currently I teach three courses in the Certificate in Web Application Development.

I can now announce that I’m also going to start teaching an online course with eClasses.org, the online learning branch of IWA/HWG. The course uses PHP and MySQL to build a shopping cart, and is aimed at intermediate PHP developers (you don’t have to know anything about MySQL, but it certainly helps if you do). I’m really lookng forward to this; you can see the full course description here, and registration is now open.

On a trip to the UK just after Christmas I succumbed to temptation and paid a visit to Toys R Us. Minutes later I walked out with this:

The eee PC

Then I headed straight for my hotel, and once in my room I could barely wait to unpack it. I’d heard it was small, but I was still staggered at just how small and light it is. I switched it on, and it booted in 15 seconds, as advertised. I ran the “First run wizard” and once that was done I clicked on “Wireless networks” and without further ado it picked up the hotel’s WiFi hotspot. Unbelievably simple; I hot-footed it to reception for a card, and within minutes was checking my email.

This is a tiny, cheap sub-notebook that runs Linux and does everything I’m likely to want to do on the move: web, email, word-processing, seamless networking. The interface is a bit Playschool, but that is clearly a deliberate choice; the machine is aimed at the educational market as a cheap, easy-to-use laptop that children can carry around with them. In any case, a browse around one of the burgeoning eee fansites quickly revealed a simple fix to enable “Advanced desktop” mode, which turns out to be exactly the same as my Xandros desktop, so no complaints there. Having said that, 90% of the time I use it in “Easy” mode.

In practice of course, many buyers seem to be geeks delighted to find a cool device that runs Linux and can be hacked to do all sorts of useful things. The result is an increasing number of sites dedicated to the eee and detailing various hacks and improvements. Always a good sign when a community builds up round something like this.

Edit: interestingly, the Xandros website states:

The Eee PC is an ASUS product and is solely supported by them, including Operating system issues. The Operating System on the Eee PC is not a Xandros Product. While Xandros may have aided in the development of the Eee PC OS, it is owned and supported by ASUS.

… but the Advanced Destop mode looks indistinguishable from Xandros.

This device really suggests that the operating system is becoming an irrelevance as long as you have network connectivity. Many users of the eee PC will not know or care what the operating system is; they’ll just use it to accomplish tasks. Microsoft must be a wee bit worried, because the eee has just launched in Japan with Windows XP pre-installed (the original model comes with instructions for installing XP, but you need a valid installation disk and another PC with a CD drive to do so). I don’t really understand why anyone would want to; as delivered the machine only has 512Mb of RAM, and runs very nicely with Linux, whereas if you want anything like acceptable performance with XP you are going to have to void the warranty by installing more memory.

But some people seem to think they should be able to do everything they could do on a heavy, bulky, 15″ notebook PC on this. It’s only got a 7″ screen for heaven’s sake; what on earth is the point of trying to run Photoshop on it? For me its role is definitely that of a supplementary PC, not a desktop replacement. It’s a huge improvement on the slow, clunky Dell laptop we lug around whenever we travel. The 15-second boot time is particularly appreciated; it means you can quickly switch it on to check something, then switch it off again to conserve the battery (battery life without wifi switched on is about three hours; slightly disappointing but over twice as long as the Dell manages). Resuming from sleep mode is even faster. Plenty of thought has been put into keeping the weight down; it also has a relatively small power adapter, similar to a mobile phone one, not the “brick” you usually get with laptops. And it’s surprisingly robust; you’d expect something as cheap as this to feel flimsy, but it doesn’t.

The one thing I don’t like about it is the small trackpad and very stiff mouse button. I don’t like trackpads much anyway, and even increasing the sensitivity doesn’t seem to help. It feels as if it’s going to be the first thing to break. Using a mouse or trackball that weighs half as much as the PC doesn’t seem to make sense, so I’ve ordered a dinky little Targus mouse for it.

We built Corbières Web almost exactly ten years ago, when we first moved to France. The primary aim was to have a site we could put in the portfolio of our budding web development company. We had a wonderful time travelling around the area taking hundreds of photos and discovering all sorts of out-of-the-way places. And we landed our first large contract as a direct result of someone seeing Corbières Web. As the first website dedicated to the area, it built up a fair amount of traffic and even won an award from the Comité Régional de Tourisme. So it certainly wasn’t a waste of time.

Then we got busy and the site got pushed so far away from the stove it wasn’t even anywhere near the back burner. I added links to it occasionally, when people emailed me and asked, and we added a few pages to it for local businesses, for a small charge. But the last time the design was touched was in 1999, and it was beginning to look a bit embarrassing. It wasn’t just the surface appearance that was old-fashioned; the code was a mess of font tags, nested tables, and invalid HTML. And this mass of 150 or so static pages was time-consuming to update, so it just didn’t get done.

I started converting it to use a CMS about a year ago in order to make updates easier, but once again didn’t have the time to complete the job. But then thanks to an online CSS workshop class he was taking, Steve picked it up as a challenge for his final project. The old design was completely scrapped and he came up with a classy new design that is valid XHTML Strict. We merged this with my work on the CMS and were able to launch the converted site within a week.

One of the challenges of the site was that it is bilingual English-French, and each page linked to its equivalent in the other language. Using SPIP for the content management means that you can easily link different language versions of the same content so that links to translations appear automatically, and when visitors choose which language they want to view the site in, that choice is automatically retained. This is the third SPIP site we’ve done, and the more I use SPIP the more impressed I am with it. Its syntax for “squelettes” (templates) and “boucles” (loops) takes a bit of getting used to, but it’s very powerful and I haven’t yet found anything I couldn’t do — even if some things require a fair amount of fiddling to get right. The documentation is superb, some of the best I’ve seen for an open-source web application, and spip-contrib is a good source of extra tips.

It’s always a real headache manipulating dates between PHP and MySQL, because PHP’s date functions assume Unix timestamps, while MySQL has its own internal date format. They both have excellent built-in functions for handling dates, but they are fundamentally incompatible. I’ve torn my hair out before now trying to manipulate dates between the two, because pretty well every application I write needs to do date arithmetic.

Well, duh, I don’t know why I didn’t think of this before, but MySQL has a UNIX_TIMESTAMP function which sorts it all out for you by converting a MySQL date to a timestamp. Simon Willison explains it, so I don’t need to. So easy when you know how!

About the only reason I ever boot into Windows on the spare PC nowadays is because I need to use Enterprise Manager or Query Analyser to manage a SQL Server database. Today it was inconvenient to reboot, because I was in the middle of doing a lot of printing. So I googled “Linux SQL Server client” and came across sqsh. Installation and set up sounded a wee bit complicated (required compiling from source), but doable, so I put it on … the back burner, with a reminder to myself to do it sometime over the next week or so.

Then later on I happened to be sitting at the Mepis PC, so I pulled up Synaptic and typed sqsh into the search field. Hey presto! Two clicks and it was installed. “Still,” I thought, “I’m bound to have to fiddle about configuring it.”

Undeterred, I typed
sqsh -Umyusername -Pmypassword -Smyservername
at the shell prompt, and a sqsh prompt appeared. If Linux doesn’t give you an error message then nothing has gone wrong. So:
use mydatabasename
go

Still no error!
SELECT * FROM mylittletable
and there were the results! Fantastic — if possibly not all that secure when used remotely :-) Highly recommended if you need occasional access to a SQL Server or Sybase database from Linux.

Want to add one (or more) days to a date in PHP? Timestamps are simply numbers of seconds, so it seems so easy and obvious to do this:
$mydate = (60*60*24)+$mydate;
or even just
$mydate = 86400+$mydate;
Don’t be tempted! Twice a year, because of daylight saving, the day doesn’t have 24 hours in it; it has 23 (spring) or 25 (autumn). So all of a sudden you are likely to find your code behaving in a manner which is downright weird. Been there, done that. The approved way is just as simple and far less likely to result in hair-tearing:
$mydate = strtotime("+1 day", $mydate);

Edit: here’s a function for calculating differences between times. Untested for resistance to DST, but could be useful in some situations. Ironically, the post he links to about calculating date difference more precisely in PHP (also untested) looks as if it does not take this problem into account. Go figure :-)

The scenario: a mixed network of Windows and Linux PCs (2 Windows XP, one Xandros, one SimplyMEPIS) which need access to edit files in a directory on one of the Linux servers. Here’s what I did: I’m not sure all the steps were necessary, but none of them is sufficient on its own!

It is taken as read that the PCs are all in the same workgroup, and Samba is installed and running on the Linux PC with the files to be shared.

1. Create users with the same name and password on all the PCs. Create a group on the Linux PCs and add the users to it (in this example the group is called editors). Note, the numeric user and group ids on the Linux boxes must be the same. If you are using a GUI interface to create users and groups, check the numbers they end up with. If they are not the same you need to use e.g.
groupmod -g 1002 editors
to change one of them to match the other. This might invalidate the group of any files belonging to users in that group, so check and reset the group if necessary, using chgrp:
chgrp -R editors www

You can make editors the default group for the users if you like, but it’s not necessary.

2. Create the directory to be shared (www in this example); it should be owned by one of the users created earlier and have the group set to editors. Use chmod to make it writable by owner and group. Now, set the sticky bit to force files to inherit the group permissions:
chmod g+s www

3. You can edit /etc/profile.d/profile (as root; the exact path of this file may vary) and change the umask line to read
umask 002

This globally forces new files to be created with group write permissions.

The steps so far have ensured that users in the editors group on the Linux box can edit files in the www directory and its subdirectories. Now you need to share the directory using Samba. Use a GUI tool if you like to set up the share (SimplyMEPIS has a nice one). But ultimately you will need to edit /etc/samba/smb.conf (as root of course) to make sure it’s set up correctly. This file is not difficult to understand, but make a backup copy first in case you trash anything. The minimum needed is the following:

4. In the [global] section, under authentication, set
security = share
This is not the most secure way, but it’s OK on a suitably small and private network. I tried using security = users, but the Xandros PC didn’t seem to like this at all; the file manager hung on opening when any of the shares were mounted.

5. In the section for the www share, force the user to be one of the users you set up earlier:

[www]
public=yes
browseable=yes
path=/opt/www
writeable=yes
force user=veronica

You might have other stuff in there, but I think this is the minimum (it was the “force user” that finally got it to work for me). If you want you can restrict access by IP address to make it more secure, e.g.:
hosts allow = 192.168.1.0/24

Don’t forget to stop and restart Samba if you have edited the smb.conf file! As root:
/etc/init.d/samba restart

6. Test by mounting the share on another PC and creating, editing, or deleting a file on the share.

Next Page »