I have a simple database on my localhost and I am following a book
I created tables in it but after I used shared file addresses i.e include ['SERVER_DOCUMENT'].'path of file'
the access to PHPMyAdmin is denied.
IT says that:
Cannot connect: invalid settings.
mysqli_real_connect(): (HY000/1130): Host ‘localhost’ is not allowed to connect to this MariaDB server
Connection for controluser as defined in your configuration failed.
mysqli_real_connect(): (HY000/1130): Host ‘localhost’ is not allowed to connect to this MariaDB server
phpMyAdmin tried to connect to the MySQL server, and the server rejected the connection. You should check the host, username and password in your configuration and make sure that they correspond to the information given by the administrator of the MySQL server.
I tried uninstalling XAMPP but when I reached the same point again on my book and did everything from start it still did the same thing
<?php
try {
$pdo = new PDO('mysql:hostname=localhost;dbname=ijdb', 'ijdbuser', 'mypassword');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->exec('SET NAMES "utf8"');
}
catch (PDOException $e) {
$error = 'Unable to connect to server' . $e->getMessage();
include 'error.html';
exit();
}
?>
index.php
<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/includes/magicquotes.inc.php';
if (isset($_GET['addjoke'])) {
include 'form.html';
exit();
}
include $_SERVER['DOCUMENT_ROOT'] . '/includes/db.inc.php';
if (isset($_POST['joketext'])) {
try {
$sql = 'INSERT INTO joke SET
joketext = :joketext,
jokedate = CURDATE()';
$s = $pdo->prepare($sql);
$s->bindValue(':joketext', $_POST['joketext']);
$s->execute();
} catch (PDOException $e) {
$error = 'Error adding submitted joke: ' . $e->getMessage();
include 'error.html';
exit();
}
header('Location: .');
exit();
}
if (isset($_GET['deletejoke'])) {
include $_SERVER['DOCUMENT_ROOT'] . '/includes/db.inc.php';
try {
$sql = 'DELETE FROM joke WHERE id = :id';
$s = $pdo->prepare($sql);
$s->bindValue(':id', $_POST['id']);
$s->execute();
} catch (PDOException $e) {
$error = 'Error deleting joke: ' . $e->getMessage();
include 'error.html';
exit();
}
header('Location: .');
exit();
}
include $_SERVER['DOCUMENT_ROOT'] . '/includes/db.inc.php';
try {
$sql = 'SELECT joke.id,name,email,joketext FROM joke INNER JOIN author ON authorid=author.id';
$result = $pdo->query($sql);
} catch (PDOException $e) {
$error = 'Error fetching jokes: ' . $e->getMessage();
include 'error.html';
exit();
}
//while ($row = $result->fetch())
foreach ($result as $value) {
$jokes[] = array(
'id' => $value['id'], 'text' => $value['joketext'], 'email' => $value['email'], 'name' => $value['name']
);
}
include 'jokes.html';
?>
I expect my joke page to be loaded.
Here is an image showing the errors I listed above:
3
Answers
I searched through internet annd found this command 'mysqld --skip-grant-tables' Executing this in the xampp shell probably resets the priviliges not sure though but got my phpmyadmin page back.
This is a case where a careful reading of the error message will help.
The phpMyadmin message is probably the most useful one. Let’s parse it.
OK, the
localhost
server is running.For some reason, the username / password combination you gave it is wrong.
YOU are the administrator of that MySQL server. Read the xampp docs and look up the username and password to use. In a new xampp installation, the default MySQL username is (or once was)
root
. The default password is a zero-length string. If you wish to use a different username/password combination from your php program, you mustYour php program logs in to MySQL. MySQL is server software that happens to be running on your local machine when you use xampp. So both it and MySQL must agree on a username/password combination.
With respect, I think you should reread the book’s section on how things are set up.
I tried with “mysqld –skip-grant-tables” in xampp shell but that was not a permanent solution because whenever I closed the shell command window the problem came back. Then I found an excellent permanent solution.
You can see the entire procedure is described here
https://www.youtube.com/watch?v=vzs9Z12OTE4
Hope this will fix your issue permanently.