I'm trying to do something that seems relatively simple, and probably is for those more experienced, but I'm still new at this and could use a little help.
I want to pull table data from another server on our LAN using ODBC and dump it into a table on my local machine(localhost). I have no problem connecting using ODBC and can run queries with no problems. I just don't know how to get it working. Here's what I've tried so far.
/* ************* CONNECTIONS ************* */
//connection variables
$username ="server";
$password ="s70van";
$ODBC_dsn ="13540";
$LOCAL_host ="localhost";
$LOCAL_database ="conduit";
//ODBC connection for the accounting database
$ODBC_conn = odbc_connect($ODBC_dsn,$username,$password);
//Check ODBC connection for errors
if (!$ODBC_conn)
{
exit("Could not connect to ODBC database");
}
//LOCAL connection for the localhost database
$LOCAL_conn = mysql_connect($LOCAL_host,$username,$password);
//Check LOCAL connection for errors
if (!$LOCAL_conn)
{
exit("Could not connect to localhost");
}
//Select LOCAL database --- */
mysql_select_db($LOCAL_database, $LOCAL_conn) or die("Can't select LOCAL database.");
/* ************* TABLE DATA TRANSFER ************* */
//Insert into query
$sql="INSERT INTO companies (sCompName)
SELECT sCompName FROM tcompany";
//Execute the insert into query
$result=odbc_exec($ODBC_conn,$sql);
//Check insert into query for errors
if (!$result)
{exit("Error in SQL");}
//Close odbc connection
odbc_close_all();
Any help would be greatly appreciated I've googled like an animal and can't find anything on this.