Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

reselect database


qwertyjjj

Recommended Posts

Posted

I have a script on my site which enters some details from orders into a remote database.

I need to flip between the local oscommerce database and the remote one to do some processing.

How can I reselect the oscommerce database with myswl_select_db after I have selected the remote one?

 

<?php
require('includes/application_top.php');

//find pending orders
$pendingorders = mysql_query ( "
SELECT orders_id, customers_email_address 
FROM orders 
WHERE orders_status = 1;
  ") or die(mysql_error());


//add db connection for the remote db
$squid_conn = mysql_connect("remote-db.aaa.aaa",
                            "user",
                            "pwd");
if (!$squid_conn)
{
	  die('Could not connect: ' . mysql_error());
}
mysql_select_db("otherdb", $squid_conn);

//if pending order is in the passwd table then
//update the order status to delivered
//put in a row in the order status history

//if pending order is missing from the passwd table
//insert a row into the remote sql db
//add a row in the order status history

//update trials status to Trial
$upd_trials = mysql_query ( "
UPDATE orders o
 JOIN orders_products op 
   ON op.orders_id = o.orders_id
  SET orders_status = 9
WHERE o.orders_status = 1
  AND op.products_id = 31
  AND op.final_price = 0;
  ") or die(mysql_error());

?>

Posted

I have a script on my site which enters some details from orders into a remote database.

I need to flip between the local oscommerce database and the remote one to do some processing.

How can I reselect the oscommerce database with myswl_select_db after I have selected the remote one?

 

<?php
require('includes/application_top.php');

//find pending orders
$pendingorders = mysql_query ( "
SELECT orders_id, customers_email_address 
FROM orders 
WHERE orders_status = 1;
  ") or die(mysql_error());


//add db connection for the remote db
$squid_conn = mysql_connect("remote-db.aaa.aaa",
                            "user",
                            "pwd");
if (!$squid_conn)
{
	  die('Could not connect: ' . mysql_error());
}
mysql_select_db("otherdb", $squid_conn);

//if pending order is in the passwd table then
//update the order status to delivered
//put in a row in the order status history

//if pending order is missing from the passwd table
//insert a row into the remote sql db
//add a row in the order status history

//update trials status to Trial
$upd_trials = mysql_query ( "
UPDATE orders o
 JOIN orders_products op 
   ON op.orders_id = o.orders_id
  SET orders_status = 9
WHERE o.orders_status = 1
  AND op.products_id = 31
  AND op.final_price = 0;
  ") or die(mysql_error());

?>

 

You could use the default functions for this i.e, tep_db_connect, tep_db_query and tep_db_close with the external server parameters. once you have closed the other connection connect back using tep_db_connect. once without parameters, it will connect to the default server ( store server ).

 

Cheers

Shiva

Our truest life is when we are in dreams awake.

-- Henry David Thoreau --

Posted

You could use the default functions for this i.e, tep_db_connect, tep_db_query and tep_db_close with the external server parameters. once you have closed the other connection connect back using tep_db_connect. once without parameters, it will connect to the default server ( store server ).

 

Cheers

Shiva

 

so when I open $squid_conn I have to do mysql_close?

Then immediately after do tep_db_connect?

Are there any paramateres to add to tep_db_copnnect?

Posted

so when I open $squid_conn I have to do mysql_close?

Then immediately after do tep_db_connect?

Are there any paramateres to add to tep_db_copnnect?

 

I am not sure if you understood what I meant ( or am I wrong ) :)

 

connect to remote database

do 1.

do 2.

.

.

.

do n.

close the connection

 

connect to store server.

 

to connect you use: tep_db_connect();

to close: tep_db_close();

 

Check the includes/functions/database.php file for exact parameter info.

 

Cheers

Shiva

Our truest life is when we are in dreams awake.

-- Henry David Thoreau --

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...