// Connect to Database $con = mysqli_connect("localhost", "username", "password", "database"); // Retrieve user information $user_id = 1; $query = "SELECT * FROM users WHERE id = $user_id"; $result = mysqli_query($con, $query); $user_data = mysqli_fetch_assoc($result); // Display user information echo "Hello, " . $user_data['name'] . "!";
// Retrieve user information from API $user_id = 1; $url = "https://api.example.com/users/{$user_id}"; $options = [ "headers" => [ "Authorization: BearerThis code example retrieves user data from an API using the PHP `file_get_contents` function and displays the user's name. Package Library: None (uses PHP built-in functions)" ] ]; $response = file_get_contents($url, false, stream_context_create($options)); $user_data = json_decode($response, true); // Display user information echo "Hello, " . $user_data['name'] . "!";