It was a season 4 episode of Deep Space 9. O'Brien is arrested on an alien world for "espionage" for asking too many innocent questions (I guess that society frowned on curiosity). He is thrown in prison, and serves what he thinks is a 20 year prison sentence where he is barely fed, and he and his cellmate have to hoard food so they don't starve during the times they "forget" to feed them. O'Brien eventually kills his cellmate over a few pieces of bread.
Then surprise! He wakes up in a chair with a bunch of blinky lights on it, and Dax and Sisko are there, and it turns out only a couple hours of real time had actually passed, and the experience was just implanted into his mind.
http://en.wikipedia.org/wiki/H...
Good episode, but I'm not sure I'd want to see that happen in real life. It caused him a lot of psychological problems.