Published on January 26, 2024By DeveloperBreeze
// Database connection parameters
$servername = 'localhost';
$username = 'username';
$password = 'password';
$dbname = 'database';
// Create a MySQLi connection
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die('Connection failed: ' . $conn->connect_error);
}
// SQL query to select all rows from the 'users' table
$sql = 'SELECT * FROM users';
$result = $conn->query($sql);
// Check if there are results
if ($result->num_rows > 0) {
// Loop through the results and display 'name' field
while ($row = $result->fetch_assoc()) {
echo 'Name: ' . $row['name'];
}
} else {
echo 'No results found.';
}
// Close the database connection
$conn->close();
Comments
Please log in to leave a comment.