In what scenarios would it be beneficial to use PHP functions like mysql_query and mysql_fetch_array for database interactions?
Using PHP functions like mysql_query and mysql_fetch_array for database interactions would be beneficial in scenarios where you need to execute SQL queries and fetch results from a MySQL database. These functions allow you to easily connect to a MySQL database, execute queries, and retrieve data in a structured format. However, it's important to note that these functions are deprecated in newer versions of PHP, so it's recommended to use mysqli or PDO functions for database interactions.
// Connect to MySQL database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";
$conn = mysql_connect($servername, $username, $password);
mysql_select_db($dbname, $conn);
// Execute SQL query
$query = "SELECT * FROM users";
$result = mysql_query($query);
// Fetch data from the result set
while ($row = mysql_fetch_array($result)) {
echo $row['username'] . "<br>";
}
// Close database connection
mysql_close($conn);