Connecting to Windows/MSSQL 2008 from Linux/CodeIgniter/PHP

Update: I’ve written a new article, covering CodeIgniter 3 and Ubuntu 14/16. Read it here.

Microsoft SQL Connecting to Microsoft SQL Express 2008 from Linux/PHP is a lot trickier than I expected. These notes are really for my own benefit so I can reproduce the setup, but maybe they’ll help you too. One of the problems is that many existing PHP drivers for MS SQL have difficulty talking to SQL 2008. Here’s a workaround using FreeTDS and ODBC.

My web application is built using CodeIgniter, the PHP application framework. It resides on an Ubuntu Server box, running Apache. Prerequisites on that Ubuntu Server (which I installed using Aptitude, but your favourite package manager will do):

  • unixODBC
  • FreeTDS
  • FreeTDS development package/(header files and libraries)

To my freetds.conf file (in /etc/freetds on my server) I added a section that looks something like this:

[my-server]
host = my.server.local
port = 1433
tds version = 9.0

Note: TDS version 9.0 should work with SQL 2008.

In /etc/odbcinst.ini, add the following ODBC driver (32-bit):

[TDS]
Driver = /usr/lib/odbc/libtdsodbc.so
Description = FreeTDS driver
Setup = /usr/lib/odbc/libtdsS.so

or 64-bit:

[TDS]
Driver = /usr/lib64/libtdsodbc.so
Description = FreeTDS driver
Setup = /usr/lib64/libtdsS.so

(You may need to check the precise location of the driver and setup files.)

And to /etc/odbc.ini, I inserted a DSN similar to the following:

[my-server]
Driver = TDS
Description = My Server
ServerName = my-server
Database = my-db

Generally within CodeIgniter, I am connecting to MySQL databases and that’s how my default connection is configured. I therefore added a second configuration to my database.php configuration file, like this:

$db['my_server']['hostname'] = "dsn=my-server;uid=myusername;pwd=mypassword";
$db['my_server']['username'] = '';
$db['my_server']['password'] = '';
$db['my_server']['database'] = '';
$db['my_server']['dbdriver'] = 'odbc';
$db['my_server']['dbprefix'] = '';
$db['my_server']['pconnect'] = TRUE;
$db['my_server']['db_debug'] = TRUE;
$db['my_server']['cache_on'] = FALSE;
$db['my_server']['cachedir'] = '';
$db['my_server']['char_set'] = 'utf8';
$db['my_server']['dbcollat'] = 'utf8_general_ci';

Now the ODBC driver within CodeIgniter can produce queries that MS SQL doesn’t like. We can fix this with a hack. You really REALLY shouldn’t do it this way (!) but to get things working and as described >here<, I edited the CodeIgniter core file system/database/drivers/odbc_driver.php. The function _from_tables() has a line reading:

return '('.implode(', ', $tables).')';

I changed it to this:

return implode(', ', $tables);

(In other words, we’re removing the spurious parentheses.)

I created a database method m_my_server.php like this:

/**
 * NOTE: We're using a feature-incomplete driver here.  Don't attempt to use
 * CodeIgniter's ActiveRecord Class or num_rows().  Use bare queries instead.
 */
class M_my_server extends Model {

  var $my_server;

  function M_my_server() {
      parent::Model();
      $this->my_server = $this->load->database('my_server', TRUE);
  }

  function get() {
    $query = $this->my_server->query('SELECT TOP(100) * FROM dbo.tblUserSummary');
    $result = $query->result_array();  // note ->num_rows() doesn't work with this driver
    if(count($result) > 0) {
      return $result;
    } else {
      return false;
    }

  }
}

/* End of file m_my_server.php */
/* Location: ./application/models/m_my_server.php */

At the SQL Server end, I set up a new standard SQL user (myusername/mypassword) rather than attempting to get Windows authentication to work (I bet it wouldn’t).

My SQL instance wasn’t listening to TCP/IP connections by default. I fired up SQL Server Configuration Manager and browsed to SQL Server Network Configuration –> Protocols for [my db instance]. Then you have to right-click TCP/IP and click Enable.

With all that in place, the following controller produces successful results:

  function SQLtest() {
    $this->load->model('m_my_server');
    $result = $this->m_my_server->get();
    if($result) {
      print_r($result);
    } else {
      echo 'nada';
    }
    exit;
  }

It’s not ideal; for one thing, bare SQL queries involve learning Microsoft’s particular dialect of SQL (whereas I’m used to MySQL). The tables I’m querying are generated by Microsoft Forefront TMG though, so I’m basically stuck with MSSQL. At least now I can query those tables from my favourite PHP application framework.

Image copyright © Microsoft. Used with permission from Microsoft.

Job Done

Steve Jobs by acaben: http://www.flickr.com/photos/acaben/541420967/sizes/l/in/photostream/Business legend Steve Jobs died late last night. I heard about it through that most modern of news outlets: Facebook. I read the story on my company-supplied iPhone (which, by the way, I didn’t want; I’d rather use the Android that I keep in my drawer – long story).

The death of Steve Jobs follows the release of the much-anticipated iPhone 4S, the successor to the iPhone 4. Perhaps that ‘S’ should stand for ‘swan song’?

This morning, I mentioned Jobs’ death to a friend, who said, “Who’s Steve Jobs?”

Who’s Steve Jobs? I guess if you’re indifferent to technology and design, you could be forgiven for not knowing his name. But whether you’ve heard of him or not, his influence has almost certainly had an impact on you. The number of modern innovations associated to his name is impressive:

  • First successful personal computer with a graphical user interface (the Macintosh)
  • First WWW (World Wide Web) server
  • Pioneering in rich content email
  • Through Pixar, the first entirely CGI film, Toy Story
  • iTunes: simple access to large online catalogue of music, incorporating digital rights management
  • iPod: user-friendly range of media players
  • iPhone: user-friendly smart phone. When asked to recommend a phone to colleagues, I suggest Android for the technophiles and iPhones for the technophobes. The success of this approach tells me everything!
  • iPad: a device that “experts” claimed was superfluous but which has shipped in phenomenal numbers, battering all manufacturers’ competition in the process
  • Obsessively well-designed low voltage power supplies (built in cable management, magnetic quick-release plugs)
  • Multi-touch mouse

Given the number of patents that bear his name, I have inevitably missed some…

I am not an Apple fanboy. In fact one of my favourite sports is baiting Apple fanboys. But I simply can’t help admiring this charismatic man who for so long helmed one of the most successful companies of all time simultaneously bringing design genius and technical excellence to the masses. Steve Jobs, one time living legend, your legacy will live on.

Meanwhile, someone somewhere just patented the iHarp.

Steve Jobs image copyright © Ben Stanfield, licensed under Creative Commons. Used with permission.

Don’t all faiths lead to God? Why is yours so special?

Assuming we’ve satisfied ourselves on the question of the existence of God and accept that He is real, the next logical question is which God and what is He like? In fact some would say, “Don’t all faiths lead to God? Why is yours so special?” And this is the issue I will attempt to address in this podcast.

Note to broadcasters: please do contact us to obtain higher quality audio and a licence to broadcast any of these podcasts.

podcast iconHow can a good God allow the innocent to suffer?

The Message: Translation, Paraphrase, Truth or Heresy?

bible

Cards on the table. Growing up as a child, I read The Living Bible, a paraphrase of the Bible that was easy to read and understand.  This was my main Bible from the ages of 4 to about 15.  I gradually transitioned to the NIV, requesting a hefty leather-bound, commentary-laden edition for my 18th birthday.

19 years and many Bible studies later, slightly the worse for wear, this remains my main (printed) Bible.  The advent of the internet and the easy accessibility of multiple versions has somewhat relegated the printed word, but my old Bible still brings with it a sense of comfort, peace and tradition – in a good way.

Of course there now exist many different versions of the Bible, all rendered with different objectives and varied levels of scholarship.   If your faith rests on the word of God (faith comes by hearing and hearing by the word of God, says Paul in Romans 10:17) it is important to know where that word may be found.

Many Christians today refer to their Bibles as “the word of God” and here we come to the heart of our discussion: In a recent sermon, I quoted some passages from The Message.  My reasoning was that I was reading a familiar passage and it is sometimes helpful to hear that passage in unfamiliar language, to ensure we don’t “switch off”.

I had not anticipated that one of my friends and someone whose spiritual integrity I trust, would question my use of The Message and further, question whether The Message even deserved the right to be called “the Bible”.  The fundamental objection is that “The Message is a paraphrase”.

Broadly we divide Bible versions into two categories: translation and paraphrase.  Doing so, we may be forgiven for thinking that there is a clear distinction between the two approaches, or that one is “superior” to another.  But I do not think that the differences are as black and white as they might appear.

As I understand it, the objective of a translator is to take a text and render it in as nearly accurate a form as possible from the source language to the destination language.  With paraphrasing, the author may start with the source language or with a pre-existing translation and then seeks to render it into a modern idiom – that is, using expressions that are particularly meaningful in a certain time and place.  (Note, the foreword to The Message states that Peterson wrote “straight from the original text”.)

It is hopefully clear that paraphrasing intrinsically involves interpretation.  The author of the paraphrase has to attempt to understand the gist of the source and predict how the source could best be understood in modern (colloquial) language.  In this case, if the author’s understanding is faulty, the paraphrase will be equally faulty.  The author considers that risk to be worth taking: If the author’s understanding is accurate, the target audience should be able to understand the paraphrase with no further assistance.  The weakness of course is that, as language develops, the paraphrase becomes outdated quickly.  Furthermore, a paraphrase into American English, say, may not result in a completely intelligible read for an Australian or British English speaker.

What may not be obvious at first glance is that translation also involves an element of interpretation, especially when the source text is an ancient language and no native speakers are alive to verify the accuracy of the translation.  In all likelihood, the source text, regardless of its age, will contain idioms and colloquialisms that would be difficult to understand without background knowledge.  A literal translation could in fact do damage to the text.  For example, a literal translation into other languages of the expression “it’s raining cats and dogs” would be unlikely to leave the reader with the impression that it’s raining heavily.  More likely, they would wonder what strange phenomenon has occurred to cause domestic pets to fall from the sky.

One further problem of translation arises: the rendering will typically require interpretation and understanding on the part of the reader.  Since the objective has not been to create a colloquial version of the text, the reader is left to apply her own understanding to the work.  With translations (as opposed to paraphrases) of ancient texts, the risk of misunderstanding the text must consequently be greater.

Where does this leave us?

Regardless of the method of rendering, it would be a mistake, I think, to describe any English version of the Bible as “God’s word”.  At best, it is a translation of God’s word.  Fortunately we have the great benefit of the Holy Spirit, who communicates with us through and in addition to our English versions of God’s word, helping us to understand the text rightly.  Is it acceptable though to refer to paraphrases such as The Message as “Bibles”?  Given the inherent difficulties of translations and paraphrases, I would not personally withhold the title “Bible” from either.  By analogy, hammers and spanners are both “tools”.  The Message and the KJV are both “Bibles”.  Which is better, a hammer or a spanner?  Neither: they are different and have different strengths and weaknesses.  Which is better, The Message or the KJV? Neither: they are different and have different strengths and weaknesses.

All translations and paraphrases share a common divine heritage blended with a human (therefore flawed) understanding.  Let us not elevate any particular version to the state of deification. Rather let us thank God for the gift of His Word and the gifts he has given his servants in translating and paraphrasing for our benefit. And further let us thank him for his Holy Spirit who will guide us into all truth (John 16:13).

Practical note: due to the strengths and weaknesses of each version, when attempting to understand a passage, it is prudent to consult a range of Bible versions and to ask the Holy Spirit to guide us in our understanding.  Also, it is helpful to be mindful of the credentials of the authors of the versions.  In the case of The Message, as with many other versions, those credentials are impressive (many scholars contributed to the final text).  This is also the reason why I would dismiss a translation such as the Jehovah’s Witness’ version of the Bible, the New World Translation – the translators’ credentials are reputedly either poor or hidden.

Bible image copyright © David Campbell, licensed under Creative Commons. Used with permission.

How to Remember the Ten Commandments

Do you struggle to remember the Ten Commandments? Would you find it tricky to remember them in order? As part of a teaching series on the Ten Commandments, I prepared some relatively easy mnemonics. You may find they help!

1. You shall have no other Gods before me.

2. You shall not make … an idol.

Remember two major “Idol” shows: Pop Idol, in the UK and American Idol in the States. (Perhaps a bit dated now!)

3. Don’t take the Lord’s name in vain.

Imagine the three wise monkeys, all determined not to blaspheme.

4. Remember the Sabbath day and keep it holy.

Visualise a four poster bed, with the words “rest” written in it. Note also there are four letters in each of the words, Holy Abba Rest.

5. Honour your mother and father.

Remember five gold rings (from The Twelve Days of Christmas) – rings being a symbol of marriage and thus parenthood. Also there are five letters in each of the words, Value Mater & Pater. (Yes I know! If it’s silly, you’re more likely to remember it!)

6. Do not murder.

Think of a grenade, roughly in the shape of a number 6.

7. Do not commit adultery.

007 is one of the most prolific adulterers in fiction!

8. Do not steal.

A bit of a stretch, I admit – imagine the 8 as part of a burglar’s mask.

9. Do not bear false witness.

Imagine someone lying down in a tennis court, holding a number 9 instead of a racquet. No lying in court! Get it? (Groan.)

10. Do not covet

Hard to explain, this one. Start with the letters “NO NV” (no envy). Take the last upright part of the first N and add put it next to the O to get 10. Then take the slant and last upright of the second N to get V and place it next to the V, for VV. In Roman numerals, V plus V is 10.

Why did God bless Jacob, the deceiver?

5369725815_9db3016c6c_b_d[1]

In the story of Jacob and Esau, Jacob, the younger twin, uses fraud and cunning to take Esau’s birthright from him. The significance of the birthright in Old Testament times cannot be overemphasised. The end result was Jacob becoming the ancestor of the Israelite people, blessed by God and Esau becoming the ancestor of some of their mortal enemies, rejected by God. On the face of it, this preferential treatment might seem unjust, if it derives from Jacob’s use of subterfuge.

But perhaps therein lies the mistake, assuming that the blessing flows from the deceitful act, rather than from a prior or independent choice of God’s. If we look back in the story, even before the birth, God had said to the boys’ mother, Rebekah:

23 …Two nations are in your womb,
and two peoples from within you will be separated;
one people will be stronger than the other,
and the older will serve the younger.

Genesis 25:23 (New International Version – UK)

And why did God choose Jacob over Esau? We may never know the full reasons, but here are a few thoughts:

  • God’s decision to bless Jacob is made prior to the children’s birth and prior to their ability to commit a sinful act. In this way, God provides an early demonstration of the principle that his favour is not based on our works.
  • God foreknew the events that would unfold. Remember that prior to Jacob deceiving his father, it is said of Esau that he “despised his birthright” (Genesis 25:34). He had sold it to his brother for some stew (probably not realising that Jacob was in earnest about taking the birthright).
  • It is possibly implied that Esau would not have honoured his bargain pertaining to the transfer of the birthright, hence Jacob’s need to take it by deception.

Whatever the real reason behind God’s choice, there are a few scriptures that cast light on his mode of operation. Firstly, the divine right of God to dispense special grace as He sees fit:

19 … I will have mercy on whom I will have mercy, and I will have compassion on whom I will have compassion.

Exodus 33:19 (New International Version – UK)

Secondly, the attitude we are expected to maintain with respect to God’s grace:

21 … The LORD gave and the LORD has taken away; may the name of the LORD be praised.

Job 1:21 (New International Version – UK)

Amd thirdly, lest we be in any doubt, our position in respect of deserving God’s favour:

10 … There is no-one righteous, not even one;

Romans 3:10 (New International Version – UK)

In short, Jacob could not have earned God’s blessing. Furthermore, we can take some comfort from the fact that God blessed him despite his behaviour. And finally, we can see that in His glorious timescale, God’s purposes will be fulfilled, even though we and our enemy try our hardest at times to defeat those purposes.


Scripture taken from the HOLY BIBLE, NEW INTERNATIONAL VERSION®. Copyright © 1973, 1978, 1984 Biblica. Used by permission of Zondervan. All rights reserved.

The “NIV” and “New International Version” trademarks are registered in the United States Patent and Trademark Office by Biblica. Use of either trademark requires the permission of Biblica.

Isaac – Brancoveanu Monastery image copyright © Fergal of Claddagh, licensed under Creative Commons. Used with permission.

A Holiday Message From Rob Pomeroy: Why I’m not an Atheist

Ricky Gervais

This year, Ricky Gervais strayed some distance from his usual field of comedy, posting a Christmas message for the Wall Street Journal, entitled Why I’m an Atheist. Within a week, the article had attracted nearly 6,000 comments.

A colleague brought my attention to the article and I’m glad he did. It was an interesting read. I commend Ricky for his honesty in expressing the reasons for his belief system at a time where personal belief seems an increasingly taboo subject.

Concerning belief, he makes a good point: “People who believe in God don’t need proof of his existence, and they certainly don’t want evidence to the contrary.” He’s right in observing the tendency to become entrenched in one’s beliefs and fearful of challenge to those beliefs. That is profoundly disappointing to me. I do not want to believe in something false, even if (as Plato observed) some good might come from that belief. No, I want to believe in something real and true, so far as such can be established. Therefore I welcome challenge to my faith. If the things I believe are true, they will stand up to any scrutiny and to the extent that I might be wrong or misguided, I want to be corrected.

Not all Christians feel the same way.

Where Ricky misses his own point is in neglecting to observe its application to him. In my experience, it is just as true to say, “People who don’t believe in God don’t need proof of his non-existence and they certainly don’t want evidence to the contrary.” Vast swathes of literature reporting miracles and the transforming effect of a personal relationship with God are dismissed out of hand. Let’s be clear: God, if He exists, is a spirit. What kind of evidence are you expecting?

But I agree with Ricky. When Christians (indeed believers of any persuasion) utter post-modern mantras like, “This is true for me,” or, “This is my reality – show me yours,” I cringe inwardly. Truth is not like that. In fact no one believes that, deep down. No one believes that the sofa that I’m sitting on has the capability of disappearing into non-existence in Schroedinger’s world between sofa and non-sofa. With the exception of a few very esoteric thinkers, we do all believe in the factual absolute truth that the sofa is not in my head.

If Jesus existed (and no serious historian now doubts that) then He was either truly God’s son or a lunatic. Let’s not be wishy-washy about that. There is overwhelming support for the fact that He made this claim. He had a reputation of performing miracles – this reputation was not confined to sympathetic or “Christian” writers. Jesus claimed to be the only way to God. There is no room in that view for half-hearted truth claims. Either Christ is the way for everyone or He’s the way for no one.

As an aside, this is where an accusation of intolerance is falsely levelled at Christianity. All world views have similar truth claims. Crusading atheist Richard Dawkins for example famously believes that parents teaching their children the truth of the Gospel are effectively committing child abuse. There’s tolerance for you. But I digress.

Let’s address the central point in Ricky’s world view: “I don’t believe in God because there is absolutely no scientific evidence for his existence and from what I’ve heard the very definition is a logical impossibility in this known universe.” This reveals that he has bought into the “enlightened” spirit of the age which wants us to believe that the only route to truth is through science. Since when did science acquire the monopoly on truth? For instance, ethics can tell us a lot about how we should practise science, but science can tell us nothing about how we should practise ethics. Science is a study of the observable universe, so it stands to reason (yes reason!) that it is in no position to comment on something unobservable or non-corporeal. If God exists, He is spirit.

I’ve recently been hearing about the Kalām cosmological argument which briefly states:

  • Everything that begins to exist has a cause.
  • The universe began to exist.
  • Therefore the universe has a cause.

Modern science does not take issue with this line of reasoning. Most cosmologists, Stephen Hawking included, believe that the universe is not eternal, that it “started” at some point in time. But we know from experience (don’t we?) that things do not just spring into existence out of nothing. It never happens. Why should the universe be any exception?

This then leads us to account for the existence of the universe: at this point we have a choice which faith statement to accept since it becomes impossible by any known method (including scientific method) to prove something beyond the sphere of our own universe. Do we believe in magic? A supreme being? Or some other idea which science is bound to hit upon eventually? At this metaphysical level the most elegant and yes, logical, account for the existence of the universe is an eternal being with will and intent. That being has to be eternal since the being cannot itself have come into existence (that would stick us with an infinite regression). That being can’t simply be matter since we know that matter has a beginning.

So the definition of God, far from being a “logical impossibility in this known universe” is a logical necessity and remains the best explanation we have to date of the fact of existence.

“Arrogance is another accusation. Which seems particularly unfair. Science seeks the truth. And it does not discriminate.” Here Ricky is confusing science with scientists. Science is practised by scientists and, I flatter myself, I have enough experience of them to detect a tendency towards arrogance, bias and discrimination. That is not unique to scientists; we all are like this.

I don’t follow why Ricky believes the burden of proof for God’s existence is on the believer. Be that as it may, believers have been demonstrating the existence of God for millennia and can hardly be blamed if non-believers refuse to accept that demonstration.

Keeping it real, Ricky’s account of the loss of his faith is poignant and saddening. He felt that his mother’s imposition of faith upon him was a sham to encourage him to behave “properly”. Darkly ironic. You see the biggest hurdle for belief in God, for many, is the poor way that believers behave. This is inconsistent with the stated underpinnings of love. Jesus when asked what the greatest commandment was replied, “Love God. And love people.”

But far more serious than Christians failing to comply with their own requirements is atheists following through the logical consequences of their belief system. If the universe is impersonal and amoral, there can be no logical defence of an absolute moral standard. Atheists can defend a moral consensus as much as they wish, but there can be no particular logical reason why a Stalin, Mussolini, Hitler or Genghis Khan should not rise up again and genocidally attempt to accelerate evolution.

If it doesn’t suit me for you to live, why should you live? The universe doesn’t care. If I’m stronger than you, why should your genetic material be given a chance to outlast mine? No moral reason. The universe doesn’t care. We all die anyway.

You say you’re trying to live a moral life. Good for you. But why should your morals have any impact on me? You’re in my space. So I’m going to kill you. That this reasoning is perfectly legitimate in the absence of an absolute moral standard cannot be disputed. You may not like it, but we’re not talking about like/dislike. We’re talking about right/wrong.

In my life I have experienced God’s intervention and known his love in a way that has surpassed coincidence and landed firmly in the realm of truth. I have tested this belief system and it has stood up to every challenge. When Christians talk about standing on a rock, this is what they mean. I embrace my faith and I embrace science. There is one important proviso: where my faith and science disagree, I have learnt to let faith preside over science. Experience has shown so far that science eventually catches up with faith, a trend I fully expect to continue, if science is indeed as honest as Ricky likes to believe.

Ricky Gervais photo copyright © Nadja von Massow, licensed under Creative Commons. Used with permission.

Kindle Fire: Pretender to the iPad’s Crown?

Kindle Fire showing InsensateWhen last week I read about the new $199 Kindle Fire released in the States, my first thought was, “This is a loss leader for a content delivery system.” Amazon has recognised it can make so much money out of selling ebooks, it doesn’t need to make a profit on the reading units.

In the Fire, Amazon has produced a unit that can in all important respects compete with most of the other tablets/pads out there, apparently (but not actually) for a fraction of the cost to the consumer. Obviously, Amazon wants to be positioned ready for when that 50:50 ebooks-to-print-books ratio tips to 75%+. And of course it’s not just ebooks, because Amazon can deliver audio, video and apps to the Fire, positioning it squarely in Apple/iTunes territory.

How is Apple going to challenge a $199 contender to the $499 iPad’s crown? I think we can be certain that Apple will respond forcefully – it can’t afford to take a drubbing in its most strategic consumer sector. Nevertheless, this looks to me like a very smart move on Amazon’s part and I’m not sure which (if any) large company is in a position to challenge this move.

It looks like PC Pro agrees with me. What do you think?

Cannot save photos on jailbroken iPhone 4 camera roll: FIXED

iPhone 4 A few applications recently started failing to save photos to the iPhone camera roll. A quick dig around via SSH confirmed this; it was not that they were saving but were somehow hidden – they were not there at all.

It seems that some kind of permissions error had crept in over time. Connecting via SSH and issuing the command “chmod -R a+rwx /var/mobile/Media/DCIM” fixed this.

NB: Be aware that this grants all users/applications read/write access to the photo directory.

iPhone 4 image copyright © ji young YOON, licensed under Creative Commons. Used with permission.

Windows: keyboard layout has changed spontaneously

keyboard I’ve recently noticed that the keyboard layout on my Windows XP PCs is spontaneously changing from UK to US. I suspect that this is linked to a piece of software I use called Input Director (which allows you to control several PCs/monitors from one keyboard/mouse).

Whatever the cause, from time to time my UK keyboard starts operating in US mode (so, for example, the following symbols are all swapped around: ", ', #, £). This is inconvenient, to say the least.

The logical place to look would be in Regional Settings/Languages, within the Control Panel. Nothing had changed there however: UK was the only layout showing as installed. Advanced Text Services were switched off and all the relevant keyboard shortcuts were disabled.

In my search for a solution, I came across this page, which describes a similar situation. Within the comments on that page, one contributor has posted:

Try holding ‘alt’ and pressing ‘shift’ three times.
alt+shift+shift+shift

The mysterious Jim doesn’t explain why this works – and I have yet to find any documentation, but, sure enough, Alt-Shift-Shift-Shift does indeed reset the keyboard layout back to UK. Further repetitions of the keyboard combo have no other effect, so this is a reset rather than a toggle.

Office has a mind of its own

Microsoft Office products can exhibit a similar behaviour. If you’re finding that some MS Office product is using the wrong keyboard map (but other programs are fine), try this: First click on the Office program, somewhere you can enter text. Then press the left shift and alt keys together. You should be returned to your default keyboard mapping.

You can actually remove the unwanted keyboard layout from Office – note this is separately managed from the Windows keyboard layout, for some reason. In one of the Office programs (for 2010 onwards), click File -> Options -> Language. If you see more than one “Editing Language” in the list, select any you don’t want and click “Remove”.

Keyboard image copyright © yum9me, licensed under Creative Commons. Used with permission.