// Establish database connection $conn = mysqli_connect("localhost", "username", "password", "dbname"); // Execute SQL statement to insert data $sql = "INSERT INTO users (name, email, phone) VALUES ('John Doe', 'johndoe@email.com', '123456789')"; $result = mysqli_query($conn, $sql); // Check if data was inserted successfully if ($result) { echo "Data inserted successfully"; } else { echo "Error: " . mysqli_error($conn); } // Close database connection mysqli_close($conn);
// Establish database connection $conn = mysqli_connect("localhost", "username", "password", "dbname"); // Execute SQL statement to fetch data $sql = "SELECT * FROM users"; $result = mysqli_query($conn, $sql); // Check if data was fetched successfully if (mysqli_num_rows($result) > 0) { // Loop through data and display it while ($row = mysqli_fetch_assoc($result)) { echo "Name: " . $row["name"] . "The PHP Database execute function is part of the PHP MySQLi extension, which is a package/library that provides an object-oriented interface for interacting with MySQL databases.
"; echo "Email: " . $row["email"] . "
"; echo "Phone: " . $row["phone"] . "
"; } } else { echo "No data found"; } // Close database connection mysqli_close($conn);