Problems with PHP connection - MySQL

2

Error

  

Warning: mysqli_connect () [function.mysqli-connect]: (HY000 / 1130): Host '10 .1.1.25 'is not allowed to connect to this MySQL server in /home/a1570220/public_html/register.php on line 2

     

Warning: mysqli_prepare () expects parameter 1 to be mysqli, boolean given in /home/a1570220/public_html/register.php on line 8

     

Warning: mysqli_stmt_bind_param () expects parameter 1 to be mysqli_stmt, null given in /home/a1570220/public_html/register.php on line 9

     

Warning: mysqli_stmt_execute () expects parameter 1 to be mysqli_stmt, null given in /home/a1570220/public_html/register.php on line 10

     

{"success": true}

Here is the code:

<?php
$con = mysqli_connect("confidencial", "confidencial", "confidencial", "confidencial");

$email = $_POST["email"];
$senha = $_POST["senha"];
$statement = mysqli_prepare($con, "INSERT INTO user (email, senha) VALUES (?, ?)");
mysqli_stmt_bind_param($statement, "siss", $email, $senha);
mysqli_stmt_execute($statement);

$response = array();
$response["success"] = true;  

echo json_encode($response);
?>

Where confidential private data is from my db so I switched.

How can I resolve this?

    
asked by anonymous 20.08.2016 / 09:49

1 answer

4

The first error is what matters most at the moment:

  

Warning: mysqli_connect () [function.mysqli-connect]: (HY000 / 1130): Host '10 .1.1.25 'is not allowed to connect to this MySQL server in /home/a1570220/public_html/register.php on line 2

This means that the host you are using for the connection is not authorized to access the DB.

In other words, even if the user and password are correct, it is necessary that in MySQL this user has permission to access the IP you are using.

For example, when creating a user with this line:

CREATE USER 'jeffrey'@'localhost' ...

You are allowing the jeffrey user to connect locally only.

CREATE USER 'jeffrey'@'%' ...

Here you are already using the "wildcard" % , which allows access from any host.

If the user has already been created, you can change the host field in the MySQL user table to avoid having to create a new user to access.

In addition to the user needing the above access, it is necessary to adjust the user's access to the tables. For example:

GRANT ALL PRIVILEGES ON *.* TO 'usuário'@'%';

Attention:

  • Normally you should not use the above line exactly as it is.

    ALL PRIVILEGES is usually a lot of privilege for a normal system user. The ideal is to allow only the necessary minimum, for example only SELECT , INSERT etc, ie only what is used;

    ON *.* is giving access to all tables and banks, in which case you owe for just what you need. It's better something like: ON db_especifico.* TO...

  • You need to run the above command as an administrator.

To effect the above change, finally execute

FLUSH PRIVILEGES;

to update the MySQL credentials.


As for the following errors, they are basically a consequence of the initial problem. The checks are missing in your application before making the query to know if each previous command was successful.

    
20.08.2016 / 10:36