What are common reasons for the error message "Benutzer '%s'@'%s' hat keine Zugriffsberechtigung" in MySQL?
The error message "Benutzer '%s'@'%s' hat keine Zugriffsberechtigung" in MySQL typically occurs when a user does not have the necessary privileges to perform a certain action on a database. To solve this issue, you can grant the required privileges to the user using the GRANT statement in MySQL.
<?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);
}
// Grant privileges to the user
$sql = "GRANT SELECT, INSERT, UPDATE, DELETE ON database.* TO 'username'@'localhost'";
if ($conn->query($sql) === TRUE) {
echo "Privileges granted successfully";
} else {
echo "Error granting privileges: " . $conn->error;
}
// Close connection
$conn->close();
?>
Keywords
Related Questions
- How can the issue of overwriting previous entries in gb.txt be resolved when adding new entries in PHP?
- What are the best practices for handling errors or displaying messages when a specific search term is not found in the file content in PHP?
- What are some common issues users face when uploading large files to a server using PHP?