$pdo = new PDO('mysql:host=localhost;dbname=my_db', 'username', 'password'); $stmt = $pdo->prepare('SELECT email FROM users WHERE id = :user_id'); $stmt->execute(['user_id' => 123]); $user = $stmt->fetch(); $email = $user['email'];
$user = User::find(123); $email = $user->email;Package library: The package library for the get_email method would depend on the framework or library being used. For example, the Laravel framework includes the Eloquent ORM which provides a user model with an email attribute, while a custom PHP application might use a PDO wrapper library like Doctrine to retrieve email from a database.