How to create pages programmatically?

Hi all,
I would like to know how to create a WordPress page programmatically. I would like to set the page title, the desc and the template to use, and create the page with PHP code. I tried to hack and directly insert rows in WordPress tables, but it failed to work properly.
Any idea is welcomed 🙂
Thanks in advance,
Nicolas