What are the differences in behavior between executing a MySQL query in PHPMyAdmin versus within a PHP script?

When executing a MySQL query in PHPMyAdmin, the query is run directly on the database server. In contrast, when executing a MySQL query within a PHP script, the query is sent from the PHP script to the database server for execution. This difference can result in variations in behavior, such as error handling, result processing, and security considerations.

// Example PHP script to execute a MySQL query
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// SQL query
$sql = "SELECT * FROM table_name";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // Output data of each row
    while($row = $result->fetch_assoc()) {
        echo "id: " . $row["id"]. " - Name: " . $row["name"]. "<br>";
    }
} else {
    echo "0 results";
}

$conn->close();
?>