You might want to take a look at the data structure of
mb_relationships table, which is quite simple and easy to understand. It has 5 columns:
ID: connection ID (auto increment)
from: the ID of the "from" object
to: the ID of the "to" object
type: the connection type (ID)
order_from: the order for the "from" side
order_to: the order for the "to" side
And based on that, you can prepare the data accordingly.
When inserting into the database manually, you can omit the
order_to for simplicity.