Hello everyone,

I am new to this community..
I have no clue how to go further with the doubt i am going to post.

I am supposed to connect to XYZ(remoteserver) which uses mysql server and fetch data from it through my localhost ABC.

I wrote my PHP script and which is running perfectly fine on localhost. But when i connect it to XYZ it shows an error saying " could not connect to SQL server on XYZ." I asked my boss. He says for many security reasons XYZ is blocked and he asked me to make a hole to get into XYZ from ABC. . I asked my boss to give privileges, he made me the admin for that XYZ server too. despite of that I am unable to connect. Could anyone throw some light on this query of mine that how to go further and get into XYZ server

here is my php script ( which is absolutely running fine on localhost)
<?php

// Database variables
$remoteServer = "XYZ";
$remoteuser = "****";
$remotepass = "******";
$remoteDB = "***";


//connection to the database
$dbhandle = mysql_connect($remoteServer, $remoteuser, $remotepass)
or die("Couldn't connect to SQL Server on $remoteServer");


//select a database to work with
$selected = mysql_select_db($remoteDB, $dbhandle)
or die("Couldn't open database $remoteDB");

//declare the SQL statement that will query the database
$query = "SELECT abc FROM xyz";

//execute the SQL query and return records
$result = mysql_query($query);

$numRows = mysql_num_rows($result);
echo "<h1>" . $numRows . " Row" . ($numRows == 1 ? "" : "s") . " Returned </h1>";

//display the results
while($row = mysql_fetch_array($result))
{
echo $row["name"];
}

//close the connection
mysql_close($dbhandle);
?>

Awaiting for some help.

Thnx
manor

<?php

// Database variables
$remoteServer = "XYZ";
$remoteuser = "****";
$remotepass = "******";
$remoteDB = "***";


//connection to the database
$dbhandle = mysql_connect($remoteServer, $remoteuser, $remotepass)
or die("Couldn't connect to SQL Server on $remoteServer");


//select a database to work with
$selected = mysql_select_db($remoteDB, $dbhandle)
or die("Couldn't open database $remoteDB");

//declare the SQL statement that will query the database
$query = "SELECT abc FROM xyz";

//execute the SQL query and return records
$result = mysql_query($query);

$numRows = mysql_num_rows($result);
echo "<h1>" . $numRows . " Row" . ($numRows == 1 ? "" : "s") . " Returned </h1>";

//display the results
while($row = mysql_fetch_array($result))
{
echo $row["name"];
}

//close the connection
mysql_close($dbhandle);
?>

Thnx Bob.. I will try to do that and will get back to u.. Thnx for quick reply.
But is it legal to dump the remote database to local machine? I know i am sounding silly..

Hi bob,

As you said to dump the database from remote serevr to local server.. which is oaky if the databse is stagnant. But the database changes every day. So i cant dump the database daily...

please do reciprocate

Thnx, manor

This article has been dead for over six months. Start a new discussion instead.