Take a look at newthread.php for an idea, more specifically, this piece of code (various lines removed for clarity)
This goes through MyBB's datahandler, so will do everything a normal new thread will do, including sending subscription emails if necessary, and will check message lengths if there are limits defined, etc. (almost) All validation and escaping will also be performed.
Note that simply adding rows will have issues, eg not updating forum counters or user post counts.
If this is being done from an external script, it's probably the easiest to include the MyBB core as well, that is:
before trying to insert threads.
Hope that helps.