FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Connecting to 2 different Mysql database and tables?





flatliner
Basicly what I am trying to do here is tranfer infromation from one Mysql database 2 another via a PHP script. The only thing about it is, that both Mysql database are on different servers, Here is the script I have got so far, but atm the secound connection isnt kicking in and its pulling info from the frist connect, I have tryed mysql_close() but still nothing. All the database selections and pass word and user name are correct also.Any idea?

Code:



<?php
// Make a MySQL Connection
$con = mysql_connect("localhost", "user", "pass") or die(mysql_error());
$con = mysql_select_db("database") or die(mysql_error());

$result = mysql_query("SELECT * FROM oakstown WHERE emailed = 'no'")
or die(mysql_error());

$total_to_be_emailed = mysql_num_rows($result);

While($row = mysql_fetch_array( $result ))
{
  array   ($doc[] = "$row[id]");


array ($date2[]                 = "$row[date]");                         
array ($invoice_name2[]           = "$row[invoice_name]" );
array ($invoice_address2[]          = "$row[invoice_address]" );
array ($telephone12[]             = "$row[telephone1]" );
array ($telephone22[]             = "$row[telephone2]" );
array ($fax2[]                     = "$row[fax]" );
array ($delivery_name2[]            = "$row[delivery_name]" );
array ($delivery_address2[]         = "$row[delivery_address]" );
array ($telephone32[]               = "$row[telephone3]" );
array ($digger_driver2[]            = "$row[digger_drivers]" );
array ($price2[]                    = "$row[price]" );
array ($payment2[]                  = "$row[payment]" );
array ($system2[]                   = "$row[system]" );
array ($distribution_box22[]        = "$row[distibution_box]" );
array ($cable2[]                    = "$row[cable]" );
array ($commission2[]               = "$row[comission]" );
array ($size2[]                     = "$row[size]" );
array ($type_of_lids2[]             = "$row[type_of_lid]" );
array ($wall_size2[]                = "$row[wall_sizes]" );
array ($wall_quantity2[]            = "$row[wall_quantity]" );
array ($facility_to_off_load2[]     = "$row[facility_to_off_load]" );
array ($facility_for_artic2[]       = "$row[facility_for_delivery]" );
array ($date_of_delivery2[]         = "$row[date_of_delivery]" );
array ($am_or_pm2[]                 = "$row[am_or_pm]" );
array ($directions2[]               = "$row[direction]" );
      
   
      };
      
   
      
   
mysql_connect("://www.flatlinesolutions.frih.net/", "user", "pass") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());


echo"seound connection<br>";

$i = "0";

While($i < $total_to_be_emailed)
{

$i = $i+1;   
   
mysql_query("INSERT INTO oakstown
( date, invoice_name, invoice_address, telephone1, telephone2, fax, delivery_name, delivery_address, telephone3, digger_driver, price, payment, system, distribution_box, cable, commission, size, distribution_box2, lid_types, l_wall_size, l_wall_quantity, facility_to_off_load, facility_for_artic, date_of_delivery, time_am_or_pm, directions, emailed, sold ) VALUES
( '$date2[$i]', '$invoice_name2[$i] ', '$invoice_address2[$i] ', '$telephone12[$i]', '$telephone22[$i]', '$fax2[$i]', '$delivery_name2[$i]', '$delivery_address2[$i]', '$telephone32[$i]' , '$digger_driver2[$i]', '$price2[$i]', '$payment2[$i]', '$system2[$i]', '$distribution_box2[$i]', '$cable2[$i]', '$commission2[$i]', '$size2[$i]', '$distribution_box22[$i]', '$type_of_lids2[$i]', '$wall_size2[$i]', '$wall_quantity2[$i]', '$facility_to_off_load2[$i]', '$facility_for_artic2[$i]', '$date_of_delivery2[$i]', '$am_or_pm2[$i]', '$directions2[$i]', '$no[$i]', '$no[$i]')")
or die(mysql_error());

};

?>
mathiaus
Having a quick look I don't like this
mysql_connect("://www.flatlinesolutions.frih.net/"

Just use frih.net and make sure that you have allowed hosts access by following my other post
http://www.frihost.com/forums/vp-397415.html#397415
flatliner
OK well I chanaged it to frih.net and try to run it then and I got this erorr

Code:

Warning: mysql_connect() [function.mysql-connect]: Access denied for user: 'Username@myipaddress and net providers name here' (Using password: YES) in C:\wamp\www\flatline database\doc_email.php on line 48

note: I removed my actually ip and net providers info.

So then I read the thread that you posted a link 2 and I went to mysql management on the DA and got to the hosting thing, but what do I put in there?
flatliner
As any1 got any more idea's what could be wrong?
mathiaus
I'm guessing you didn't also follow the instructions in the link. You need to add a wildcard % (the percentage sign) to the allowed hosts.
flatliner
I did read it but I didnt fully understand it, like put this %216.32.85.170 in the add host section and then what do I put in my connection?

Code:

// Make a MySQL Connection
mysql_connect("frih.net", "user", "passs") or die(mysql_error());
mysql_select_db("db) or die(mysql_error());
mathiaus
Just use the percentage sign, no need for anything else. Your settings within the script look correct.
flatliner
still getting this erorr

Quote:


Warning: mysql_connect() [function.mysql-connect]: Access denied for user: 'database_username@myip' (Using password: YES) in C:\wamp\www\flatline database\doc_email.php on line 4

mathiaus
Are you using the same login details that work for phpmyAdmin?
ie username is your DAusername, an underscore, then the database username?
flatliner
yes the username is the same as the phpMyadmin log in , same with the password
flatliner
Edit: Never mind, I tryed with another mysql server I have and it work fine thanks for the help
snowboardalliance
Not related to MySQL, but I think that for this part of your code...

Code:
  array   ($doc[] = "$row[id]");


array ($date2[]                 = "$row[date]");                         
array ($invoice_name2[]           = "$row[invoice_name]" );
array ($invoice_address2[]          = "$row[invoice_address]" );
array ($telephone12[]             = "$row[telephone1]" );
array ($telephone22[]             = "$row[telephone2]" );
array ($fax2[]                     = "$row[fax]" );
......


You should just use

Code:
 $doc[] = $row['id'];


$date2[]                 = $row['date'];                         
$invoice_name2[]           = $row['invoice_name'] ;
$invoice_address2[]          = $row['invoice_address'] ;
$telephone12[]             = $row['telephone1'] ;
$telephone22[]             = $row['telephone2'] ;
$fax2[]                     = $row['fax'];
//etc
flatliner
oh yea, well it works fine the way it is so I dont really mind, but thanks anyway Very Happy
Related topics
Cron Job to Backup MySQL Database
Mysql database problem
PHPBB MYSQL Database Question.
MySQL database for a forum
Mysql database size?
Connect to MySql database
A very good PHP MySQL Tutorial
[MySQL database] Password and username
insert data to mySQL database problem
MySQL Database!?
Error connecting to mysql ; please help
Problem connecting to MySQL database with PHP [RESOLVED]
Is there a better way to restore mysql database?
Connecting to a MySQL database using Python
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.