0

Hi i have a problem connecting with my Mysql database i have the following code:

<?php
$servername = "dt5.ehb.be";
$username = "TVOSAPP";
$password = "*****";
$dbname = "TVOSAPP";

// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

$sql = "SELECT storyId, title, score FROM Stories";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        echo "id: " . $row["storyId"].  "Naam" . $row["title"]. "score" . $row["score"]. "<br>";
    }    
} else {
    echo "0 results";
}
mysqli_close($conn);
?>

which gives the following error:

Connection failed: Access denied for user 'TVOSAPP'@'10.3.101.30' (using password: YES)

I hope you can help me out to solve this problem it would be very much appreciated

Manoj Sharma
  • 1,467
  • 2
  • 12
  • 20
ArnoP
  • 33
  • 5
  • 2
    Can you connect with the information directly? Username and db name are the same? – chris85 Jan 16 '17 at 00:02
  • 1
    Possible duplicate of [MySQL ERROR 1045 (28000): Access denied for user 'bill'@'localhost' (using password: YES)](http://stackoverflow.com/questions/10299148/mysql-error-1045-28000-access-denied-for-user-billlocalhost-using-passw) – scrowler Jan 16 '17 at 00:04
  • 1
    Is this a school assignment? Because you're trying to connect to a school DB. – Xorifelse Jan 16 '17 at 00:04
  • 1
    I hope you're using an actual password in place of `*****`. – shmosel Jan 16 '17 at 00:10
  • I am using a real one its cuz its a life project that i blanked it out and yeah both username and DB name are the same – ArnoP Jan 16 '17 at 00:40
  • And i can acces my DB information through phpmyadmin so it the username and pasword should work i just really have no clue why it doesn't work – ArnoP Jan 16 '17 at 00:43

2 Answers2

0

the user that you are trying to connect with might not have the permission to connect remotely to the DB. please verify the same. To give remote access you might need to run

grant <privilage name> on TVOSAPP.* to 'TVOSAPP'@'<youripaddress>' identified by <yourpassword>

Ref: http://dev.mysql.com/doc/refman/5.7/en/grant.html

EDIT:

If your IP address is not static then you can use a percentage sign (%) in place of your IP address. However this approach is less secure as it allows any host to connect to the database remotely.

sid-m
  • 1,266
  • 11
  • 19
  • it gives me the following error #1044 - Access denied for user 'TVOSAPP'@'%' to database 'TVOSAPP' – ArnoP Jan 16 '17 at 08:53
0

I fixed it about a week ago is had a space too much thats why I couldn't connect thank you all for your responses

ArnoP
  • 33
  • 5