skip to Main Content

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:

image

3

Answers


  1. Chosen as BEST ANSWER

    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.


  2. 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.

    phpMyAdmin tried to connect to the MySQL server, and the server rejected the connection.

    OK, the localhost server is running.

    You should check the host, username and password in your configuration

    For some reason, the username / password combination you gave it is wrong.

    and make sure that they correspond to the information given by the administrator of the MySQL server.

    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 must

    • add that new username/password combination to your MySQL server, logging in from phpmyadmin with the old username to do that. Here’s a suggestion about that.
    • update your db.inc.php file or whatever in your php application gives the username/password.

    Your 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.

    Login or Signup to reply.
  3. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search