|
Answer» I am using 000webhost.com as my free and trial web hosting. When I try to connect to the database server, it says Access denied for the [email PROTECTED]
(I have replaced the servername, userid and password with my actual and correct information)
$con = mysql_connect("server name","userid","password"); if (!$con) { die('Could not connect: ' . mysql_error()); }
echo "Connected to database"; ?> Well if access is denied, it simply means you have a wrong username of password. The host/server is usually localhost - is this what you used?no. 000webhost is telling me not to use 'localhost' and they give their own host name which I am using. But still not working.Try setting them as variables first.
Code: [Select]<?php
$host = ""; $user = ""; $pass = "";
if(!$con = mysql_connect($host, $user, $pass) { die("Could not connect: " . mysql_error()); }
?> Same error. No change Have you tried changing your username or password?I did but it didn't work still I don't know so...
Maybe you should try contacting them DIRECT or try their forum.This happens to everyone, and pretty much no one has FIXED it, or got it to work.Please ANYBODY reply... I am still facing same problem. Is there anyone who has confronted such problem and solved it Did you contact their support?of course kpac. I have made EVERY possible effort from my side. I contacted two hosting services, but neither could solve my problem. They just said that don't use "localhost" in place of hosting server name. I told them that I am already not doing that... Then they asked to contact some professional....I am using the same 000webhost.com
I am using the below method and it works fine
mysql_connect("mysql123.000webhost.com", "a701646_dbusrname", "pass") or die(mysql_error()); echo "Connection to the server was successful! ";
mysql_select_db("a701646_dbname") or die(mysql_error()); echo "Database was selected!
";
$result = mysql_query("CREATE TABLE `users` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `name` VARCHAR(100) DEFAULT NULL, `city` VARCHAR(100) DEFAULT NULL, `web` VARCHAR(100) DEFAULT NULL, `age` SMALLINT(6) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=INNODB DEFAULT CHARSET=latin1");
echo $result; ?> Thank you very much Bukhari. It is working.
The difference I see here is that you are not assigning mysql_connect to a variable and directly doing it. Don't know whether this is a problem or what else?
Anyways, Thank you very much.mention not
welcome
|