What is the significance of using the mysql_query() function when interacting with a database in PHP?
The mysql_query() function is significant when interacting with a database in PHP because it is used to send a SQL query to the database. This function allows you to perform various operations such as inserting, updating, deleting, and retrieving data from the database. It is essential for executing SQL queries and fetching results in PHP applications.
// Establish a connection to the database
$connection = mysql_connect("localhost", "username", "password");
mysql_select_db("database_name", $connection);
// Execute a SQL query using mysql_query()
$result = mysql_query("SELECT * FROM table_name");
// Fetch data from the result set
while ($row = mysql_fetch_array($result)) {
echo $row['column_name'] . "<br>";
}
// Close the connection
mysql_close($connection);