I am interested in how variable scope works with mysqli prepared statements. For example:
$link = new mysqli("localhost", "root", "password", "db");
$stmt = $link->prepare("SELECT name, age, state FROM users WHERE id=?");
Now I know I need to use the bind_param() and bind_result() methods, but I don't know where/how...
$stmt->bind_param("i", $id);
$stmt->bind_result($name, $age, $state);
Should these be used every time I would like to use the statement, or only once? And what is the scope of the variables $id, $name, $age, $state?
If I want to set up the link, and prepare the statements at the begining of the document, how do I use the statements within a function, and handle the scope of the parameters and results?