Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strange Problem accessing MySQL table on two different hosts 1

Status
Not open for further replies.

Muppsy007

Programmer
Joined
Apr 4, 2003
Messages
98
Location
NZ
Hello, this is a bit of a wierd one, so please bear with me. Here's the setup.

1. We've got two sites, hosted by two different Hosts, but both sites are owned by the same person. I'll call these Mother and Child.

2. Mother has been running for a while and has a MySQL area with 6 tables for various tasks. All scripts on mother access the tables via 'localhost'.

3. Child is a new site, but has a form in common with Mother.

4. We want to directly log data entered on both these forms on the one NEW table on Mother's host called DMA_Log. Both forms also have to generate an ID number by getting the next available number from another NEW table called DMA_ID and adding some text to the front of it.

5. Here is the code that performs this action:
// Connect to database
$db = mysql_connect("secure.host.com","user","pwd");

// PART ONE - Work out the next DMA ID code so it can be entered into the DB with the rest of the info//

mysql_select_db("emed",$db);
$IDtable = "DMAID";
$IDquery = "SELECT * FROM DMA_ID";
$DMA_CODE = mysql_query($IDquery) or die (mysql_error());

if($resultrow = mysql_fetch_array($DMA_CODE))
{
$number = $resultrow["NEXT_ID"];
}while($resultrow = mysql_fetch_array($DMA_CODE));

// Now assing the Next ID number and add the DMA part of it to the variable//
$NextID = 'DMA' . $number;

// Finally, increment the ID number ready for the next user//
$newNumber = $number + 1;
$updateID = "UPDATE `DMA_ID` SET `NEXT_ID`= '$newNumber';";
$results = mysql_query($updateID);

// END OF PART ONE - DMA CODE CREATED//


Now, the only changes that are made to this script between sites is that the Child site connects to "secure.host.com" and the Mother site connects to "localhost".

Now this is the weird part. The script works perfectly on the Child site. But when run on the Mother site it can simply not find the DMA_ID table.

I have substituted DMA_ID with another table that the Mother site uses and the error goes away.

Any Ideas why the external site can see the table but the local site cannot?

Thanks for any help
Aaron
 
I would recommend at first that you add proper sucess check for each of the MySQL statements that could fail:
Code:
$db = myql_connect($host,$user,$pass) [COLOR=red] OR die("Cannot connect: ".mysql_error());[/color]
etc.
So we can see if the connection for example is made successfully.
 
Thanks for the help DRJ.

Just got it sorted. I rang the host who runs the MySQL database and it seems they had an old copy of our database running on the unsecure server for some strange reason. So calling localhost from this page gave the impression of connecting.

It's all go now though

Thanks
Aaron
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top