Hi all, I woudl like to connect to website database from localhost,which means displaying the databse of the site to my localhost pages, and here is the code: $con =@ mysql_connect("http://www.sitename.com" ,"username" ,"password" ) or die (mysql_error()) ; $db = mysql_select_db ( "Website_DB" , $con)or die ("Database not found" ) ; $result = mysql_query("SELECT * FROM Customers ") or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo $row['FirstName'] . " " . $row['LastName']; echo "<br />"; } PHP: so excuting this code I get an error: "Unknown MySQL server host 'http' (11001)" . Any help please ????
remove http:// and just use www.sitename.com http:// is a protocol specification and not part of the host name. for localhost you could also use the word localhost or 127.0.0.1, but you will also need to enter the username and password not just the words "username" and "password" something like: $con = mysql_connect("127.0.0.1" ,"mysql_user" ,"xpd911" ) or die (mysql_error()) ;
Thanks shofstetter, if I use $con = mysql_connect("127.0.0.1" ,"mysql_user" ,"mypassword" ) or die (mysql_error()) ; the local serever (xampp) think that I am calling to it, and I am not colling to it I would like to call the website server (www.mysitename.com), and I get this error "Access denied for user 'mysql_user'@'MyIPaddress' (using password: YES)".
your mysql user does not have permission to access the database from your location. You will have to add the permissions to your database user to grant it remote access. http://www.debianhelp.co.uk/remotemysql.htm
Thank u again, but I need to ask , when I do all the steps , can I use my localhost server and wwwsitename.com server at the same time , because there is some pages using internet database and some aother pahes using localhost database. dont surprise my question , but the system that I am doing needs both database( localhost DB and Site name DB )
Thanks shofstetter very much I enabled remote accecss from the CPanel then it work . thank u again 4 ur time