Page 1 of 1

Error connecting to database on host

Posted: Wed Feb 12, 2014 3:25 am
by vxmordor

Code: Select all

$isplayer2=mysql_query($isplayer) or die("Could not query players table");
$isplayer3=mysql_fetch_array($isplayer2); 
The lines above cause this error because it's password protected, what is the correct code for a password protected DB?
-------------------------------------------------------------------------------------------------------------------------------------------
Warning: mysql_query() [function.mysql-query]: Access denied for user 'a9351365'@'localhost' (using password: NO) in /home/a9351365/public_html/reguser.php on line 23


PHP Error Message

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/a9351365/public_html/reguser.php on line 23


Could not query players table

-------------------------------------------------------------------------------------------------------------------------------------------
This is what I had to use for the connect page

Code: Select all

<?php

// Create Connection
$db=mysqli_connect("mysql5.000webhost.com","a9351365_mo","removed","a9351365_mo");

// Check connection

    if (mysqli_connect_errno())
{
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

?>

Re: Error connecting to database on host

Posted: Wed Feb 12, 2014 4:40 am
by Jackolantern
I broke your post off from the thread you had posted it in, since the thread was very old and it had nothing to do with that thread.

As for your issue, I believe with 000webhost they have to give you the password, if I recall correctly. I know they have to give you a lot of the info for you to access the db. Maybe someone else could confirm or correct that who has used them more recently. If not, it should be somewhere in the documentation for the host.

Re: Error connecting to database on host

Posted: Wed Feb 12, 2014 5:21 am
by vxmordor
The issue is not obtaining the password. I created that. The issue is the code from the tutorial expects the database not to have a password. I believe that is the reason for the error message.

The example on the bottom shows a work around which does access the database correctly.

This also works correctly which verifies that database is connected

<?php
include 'connect.php';

$result = mysqli_query($db,"SELECT * FROM players");


echo "<table border='1'>

<tr>

<th>Player Name</th>
<th>E-mail</th>
</tr>";



while($row = mysqli_fetch_array($result))

{

echo "<tr>";

echo "<td>" . $row['name'] . "</td>";

echo "<td>" . $row['email'] . "</td>";

echo "</tr>";

}

echo "</table>";

mysqli_close($db);

?>

Re: Error connecting to database on host

Posted: Wed Feb 12, 2014 7:49 am
by vxmordor
Fixed: This is the working info

$db = mysql_connect("mysql5.000webhost.com","a9351365_mo","removed") or die("Could not connect to db");

There are several syntax options, this one worked.

Re: Error connecting to database on host

Posted: Wed Feb 12, 2014 5:16 pm
by hallsofvallhalla
i was going to say when it says "using the password no" means you left it blank yet it has one.