Error connecting to database on host

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
vxmordor
Posts: 11
Joined: Wed Feb 12, 2014 3:21 am

Error connecting to database on host

Post 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();
}

?>
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Error connecting to database on host

Post 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.
The indelible lord of tl;dr
vxmordor
Posts: 11
Joined: Wed Feb 12, 2014 3:21 am

Re: Error connecting to database on host

Post 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);

?>
vxmordor
Posts: 11
Joined: Wed Feb 12, 2014 3:21 am

Re: Error connecting to database on host

Post 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.
User avatar
hallsofvallhalla
Site Admin
Posts: 12023
Joined: Wed Apr 22, 2009 11:29 pm

Re: Error connecting to database on host

Post by hallsofvallhalla »

i was going to say when it says "using the password no" means you left it blank yet it has one.
Post Reply

Return to “Beginner Help and Support”