Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Select quantity from other database


Xterminator

Recommended Posts

Hi!

 

I'm trying to query another MySQL database to get the quantity of the products. The reason for this is simply to stay 100% syncronised with our supplier.

 

Here is my edited part from general.php

 

////

// Return a product's stock

// TABLES: products

function tep_get_products_stock($products_id) {

 

$myresult = tep_db_query("select products_model from products where products_id = '" . $products_id . "'");

$mynr = mysql_result($myresult,0,"products_model");

 

 

tep_db_close();

 

$otherserver = mysql_connect("www.otherserver.com", "user", "pass");

mysql_select_db("database",$otherserver);

 

$prodresult = tep_db_query("select products_id from products where products_model LIKE '" . $mynr . "'");

 

 

 

$products_id = mysql_result($prodresult,0,"products_id");

 

 

 

$products_id = tep_get_prid($products_id);

$stock_query = tep_db_query("select products_quantity from " . TABLE_PRODUCTS . " where products_id = '" . $products_id . "'");

$stock_values = tep_db_fetch_array($stock_query);

 

 

return $stock_values['products_quantity'];

 

 

mysql_close($otherserver);

 

tep_db_connect();

 

 

}

 

And this works like a charm, with the products model number as the unique identifier between the databases. UNTIL I have two or more products in the basket. Then I get this error message:

 

Warning: mysql_query(): 6 is not a valid MySQL-Link resource in /home/mgmwebn/public_html/catalog/includes/functions/database.php on line 44

0 -

 

select products_id from products where products_model LIKE '100273'

 

[TEP STOP]

 

 

Warning: mysql_query(): 6 is not a valid MySQL-Link resource in /home/mgmwebn/public_html/catalog/includes/functions/database.php on line 44

0 -

 

select count(*) as total from sessions where sesskey = 'c9c46eb93e092be8213e74d34fd3d504'

 

[TEP STOP]

 

 

Warning: Unknown(): A session is active. You cannot change the session module's ini settings at this time. in Unknown on line 0

 

And question number two: This only checks the quantity when viewing the basket, where do I implement this fuction to make it work everywhere?

 

Help is greatly appreciated!

- Mads

Link to comment
Share on other sites

In between tep_db_close() and tep_db_connect(), I would not use the tep_db_ functions to access the database. Instead, I would use the standard PHP functions. Also, I'm not sure that you need to close the database. I think it would be sufficient to open a new database with a new handle.

 

Hth,

Matt

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...