I may be wrong, but what I found (for l2off) is this:
In the MS-SQL database there is an id for the item a user has (user_item table). In the pet_data table, there is also an id field. While there is no apparent linkage between these fields in the DB structure, you will see that the pet's id matches exactly the id of the colar/flute for that pet!
I am not aware of the insides of this and if it will work by just changing the pet's npc_id, or how to do any of that, but since you were looking for a link between item and pet, this is one

Perhaps the code looks at more things than just that, though. I recommend you use caution.