How to create a caldav client and send appointment to ownCloud?

No, I want to write a server routine, that runs every hour or so and synchronizes calendar items from my therapy-database to the ownCloud server.
As I said, I tried to do a direct “database to database” synchronization via triggers or sql procedures, but that only works, if both databases are on the same server.
Moreover: The synchronization from the ownCloud to mobile devices fails frequently and I had the suspicion, that this happens because something is missing, if I write directly to the db.