For the needs of the upcoming flight to Phobos within the framework of the project Phobos-Grunt, a dynamical numerical theory of the motion of Phobos is developed on the basis of Earth-based and spacecraft (SC) optical measurements and Earth-based radio observations of the SC motion. The theory uses the most reliable astronomical constants. Within the framework of a unified dynamical model, an algorithm is proposed for the joint correction of Phobos and the spacecraft parameters of motion, among which are the secular acceleration of Phobos and its gravitational constant. The accuracy of the obtained ephemeris is estimated for the time of the SC arrival to Phobos.