You could put 'expiry' date/time set +1 hour in future in DB and when checking code check against it.
Because it's such a limited use feature and because there's time limit on after which you don't have to worry about extra codes being stored in DB, you could run clean-up script once a day or once a month even.
It's usually done via CRON job on server side, that calls
php /pahttoyourproject/index.php cron/cleanup from command line.
Just make sure you check that such controllers are only called from command line, think the helper function for that in CI was is_cli().