// Connect to database $conn = mysqli_connect("localhost", "username", "password", "database_name"); // Select data from table $sql = "SELECT name, email, phone FROM users"; $result = mysqli_query($conn, $sql); // Fetch data as associative array while ($row = mysqli_fetch_assoc($result)) { echo "Name: " . $row["name"] . ", Email: " . $row["email"] . ", Phone: " . $row["phone"] . "
"; } // Close database connection mysqli_close($conn);
// Connect to database $pdo = new PDO("mysql:host=localhost;dbname=database_name", "username", "password"); // Select data from table $stmt = $pdo->query("SELECT name, email, phone FROM users"); // Fetch data as associative array while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { echo "Name: " . $row["name"] . ", Email: " . $row["email"] . ", Phone: " . $row["phone"] . "In this example, we connect to a database using PDO and query a table called "users". We then use a while loop to iterate through each row of the result set and echo the values of the "name", "email", and "phone" fields. Package/Library: This function is provided by the PDO extension, which is also included in the PHP core.
"; } // Close database connection $pdo = null;