user. I have to connect it with mysql. How i can do it?
use ORM, e.g. Doctrine
I do this with MVC, here is an example: A model called UserModel.php: class UserModel { public static function getAllPosts() { $database = DatabaseFactory::getFactory()->getConnection(); $sql = "SELECT user_id, user_name FROM users "; $query = $database->prepare($sql); $query->execute(array(':user_id' => Session::get('user_id'))); // fetchAll() is the PDO method that gets all result rows return $query->fetchAll(); } } Call the controller simply with UsersModel::getAllUsers()
Обсуждают сегодня