Jump to content

is there a way of connecting to a database on a server from a local computer?


Recommended Posts

I have this script below

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <meta http-equiv="content-type" content="text/html; charset=windows-1250">
  <meta name="generator" content="PSPad editor, www.pspad.com">
  <title></title>
  </head>
  <body>
<?php
  $hostname = "hostname";
  $database = "database";
  $user = "user";
  $pass = "pass";
  

  
  $dbcn = mysql_connect($hostname, $user, $pass);
  if(!$dbcn)
  {
    exit ("<p>Error connecting to the site database.</p>");
  }
  
  $dbsel = mysql_select_db($database, $dbcn);
  if(!$dbsel)
  {
    exit ("<p>Error opening the site database.</p>");
  }
  
  $result = mysql_query("SELECT * From password",$dbcn);
  if(!$result)
    {
    die("Database query failed: ".mysql_error());
    }
    
  while($row = mysql_fetch_array($result))
    {
    echo $row["mypass"]."<br />";
    }
    
  
  mysql_close($dbcn);
  
?> 
  </body>
</html>

 

When i upload the code to a server it works grand but is there away i can view whats in the database if i run the script on my own local apache server..

 

Im getting this error

 

Warning: mysql_connect() [function.mysql-connect]: Can't connect to MySQL server on 'server name' (10060) in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\testing\testing.php on line 17

 

Error connecting to the site database.

 

Thanks for any help ye can provide..

You would need to authenticate your WAN IP on the MySQL server your trying to connect to.  In other words, you would need to add ANOTHER USER to this "server name"  that has the credentials of your local computer. (i.e. your WAN IP)

Yeah. If your server is on a CPANEL account you can do this very simply

Go into the Remote MySQL in the Database panel and then add the wildcard % to the allowed hosts. Once you have, it should work fine

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.