What is a correct phrase: “bind to” or “bind with”? If both are correct, when should I use the first form, and when the second?
They are both correct. However, they are used in different instances
"Bind to", is used to describe the action of tying or attaching an object to another object. E.g., Take the knife, and bind it to your leg.
"Bind with" is used to describe the thing which is used to tie or attach the object. E.g. "I will bind the knife with a rope.
One is used with the object the action is performed upon, and the other is used with the object performing the action.
Both are correct but mean different things, the most concrete meanings:
Ulysses was bound to the mast. The object here, (the mast), would typically be larger or more stable.
He was bound with rope. The object here, (rope), is the means of binding.
There is a range of idiomatic uses and similar phrasal verbs, such as:
He was bound to fail. Meaning the outcome was inevitable. In this case the to might be seen as part of the infinitive to fail, certainly it needs to be followed by a verb in infinitive form.
His failure was bound up with his preconceptions. This implies a complex or ongoing relationship between the outcome, (failure), and some other factor, (his preconceptions).
Noticing that the answers you have so far been given are all for the literal meaning of "tie with rope" and the like, in which context the two phrases are unlikely to be confused, I am guessing that you are asking about a different sense, in logic, computer-science, linguistics etc, and are asking about about binding values to variables and similar concepts.
If I am right, then there is no clear answer, because this is a rather recent and specialised bit of jargon, and not part of general English at all.
I would generally use "bind to" in this sense, expect perhaps where the relationship is symmetrical, when I might say that the two elements bind with each other.