How can access permissions for a MySQL server be changed in PHP?

To change access permissions for a MySQL server in PHP, you can use the GRANT statement to assign specific privileges to a user. This can be done by connecting to the MySQL server using a privileged account and executing the GRANT statement with the desired permissions for the user in question.

<?php
$servername = "localhost";
$username = "root";
$password = "password";
$dbname = "myDB";

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

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

// Grant SELECT, INSERT, UPDATE privileges to a user
$sql = "GRANT SELECT, INSERT, UPDATE ON myDB.* TO 'user'@'localhost' IDENTIFIED BY 'password'";
if ($conn->query($sql) === TRUE) {
    echo "Permissions granted successfully";
} else {
    echo "Error granting permissions: " . $conn->error;
}

$conn->close();
?>