Store database value in variable using php

For example. I have a select statement that is "select ID from students where student name ='name';"

Now I don't wanna echo the student ID but I wanna store it in various where I can reuse it. How do I do it.