Warning: mysql_connect(): (HY000/2002): Connection refused in /home/vol14_1/byethost31.com/b31_16461744/htdocs/Mysql/con.php on line 7
Warning: mysql_select_db(): No such file or directory in /home/vol14_1/byethost31.com/b31_16461744/htdocs/Mysql/con.php on line 8
Warning: mysql_select_db(): A link to the server could not be established in /home/vol14_1/byethost31.com/b31_16461744/htdocs/Mysql/con.php on line 8
I have the below code
<?php
$localhost="localhost";
$username=b31_16461744;
$pass=test123;
$dbname=b31_16461744_user;
$a= mysqli_connect($localhost,$user,$pass);
mysql_select_db($dbname);
if($a)
{
echo "connected..";
}
else
{
echo "not...!!";
}
?>
I Think Credentials are not correctly set. See Your connection statement. For Reference : While Working On Localhost, We write connection statement as :
But, While working on server, we need to change the following credential. Username and password values are must.
Sidenote: Assuming the credentials are correct, given to you by your web host.
There are several problems with this code (taken from a comment you left).
Firstly, three of your declarations are not quoted and are being treated as constants.
PHP error reporting would have thrown notices of undefined constants.
These are treated as constants:
You are also referencing the wrong variable for the username being
$user
which should be$username
. Error reporting would have signabled an undefined variable notice.Then you're mixing
mysql_
withmysqli_
syntax. Those different MySQL APIs do NOT intermix. You must use the same one throughout your code.Sidenote: The other question you posted Access denied for user 'test123'@'192.168.0.38' (using password: NO) you are using
sql306.byethost31.com
for the host. Make sure that is correct. I have no idea what settings that host wants you to use.or just use all four parameters:
However, your
else
with the echo does not help you. Usemysqli_error()
to get the real error.I.e.:
or die("Error " . mysqli_error($a));
Example from the manual
References:
Add error reporting to the top of your file(s) which will help find errors.
Sidenote: Displaying errors should only be done in staging, and never production