qwertyjjj
11-04-2012, 07:12 PM
I get a
mysql_num_rows(): supplied argument is not a valid MySQL result resource
error on the bold line.
Can't figure out why and can't see any error in the SQL.
//////////////////////////////////////////////
// FIND ANY ORDERS THAT WERE MARKED AS DELIVERED
// BUT HAVE NOT BEEN MADE ACTIVE IN SQUID OR OPENVPN TABLES
//////////////////////////////////////////////
$db_selected = mysql_select_db("AAAAA", $squid_conn_int);
if (!$db_selected) {
mail('AAAAA@AAAAA.co.uk', 'IntegrityCheck script error', mysql_error().' error');
die ('Can\'t use database: ' . mysql_error());
}
$result = mysql_query("
SELECT orders.orders_id , orders.customers_id , orders.customers_name , orders.customers_email_address , orders.payment_method , orders.last_modified ,
orders.orders_status , orders_products.products_id, products_description.products_name
FROM orders
INNER JOIN orders_products ON orders_products.orders_id = orders.orders_id
INNER JOIN products_description ON products_description.products_id = orders_products.products_id
WHERE orders_status =3
AND last_modified > NOW( ) - INTERVAL 120 MINUTE
ORDER BY orders_id DESC" , $squid_conn_int
);
if (mysql_num_rows($result) > 0) {
while ($box = mysql_fetch_array($result, MYSQL_ASSOC)) {
//if found, take order ID and products id
$oid = $box['orders.orders_id'];
$custid = $box['orders.customers_id'];
$prodid = $box['orders_products.products_id'];
//if proxy, check if active in squid
mysql_select_db("squid", $squid_conn_remote);
if (!$db_selected) {
mail('AAAAA@AAAAA.co.uk', 'IntegrityCheck script error', mysql_error().' error');
die ('Can\'t use database: ' . mysql_error());
}
if ($prodid == 31 ||
$prodid == 28 ||
$prodid == 29 ||
$prodid == 34 ||
$prodid == 40 ||
$prodid == 32)
{
$newresult = mysql_query('SELECT customers_id FROM passwd WHERE customers_id = '.$custid.' AND enabled = 0 AND UpdateOnNextCycle = 0', $squid_conn_remote)
or die (mysql_error());
}
mysql_select_db("squid", $squid_conn_remote);
if ($prodid == 37 ||
$prodid == 38 )
{
$newresult = mysql_query('SELECT customers_id FROM OpenVPN WHERE customers_id = '.$custid.' AND enabled = 0 AND UpdateOnNextCycle = 0', $squid_conn_remote)
or die (mysql_error());
}
if (mysql_num_rows($newresult) == 0) {
//if not active in squid or VPN then connect to OSC database
//delete anything in orders status history with 1
//change status in orders to 1
$db_selected = mysql_select_db("AAAAA", $squid_conn_int);
if (!$db_selected) {
mail('AAAAA@AAAAA.co.uk', 'IntegrityCheck script error', mysql_error().' error');
die ('Can\'t use database: ' . mysql_error());
}
mysql_query("DELETE FROM orders_status_history WHERE orders_id = ".$oid." AND customer_notified = 1", $squid_conn_int)
or die (mysql_error());
mysql_query("UPDATE orders SET orders_status = 1 WHERE orders_id = ".$oid, $squid_conn_int)
or die (mysql_error());
//these orders will now be picked up by the next IntegrityCheck run in the top part of this script
}
}
}
mysql_num_rows(): supplied argument is not a valid MySQL result resource
error on the bold line.
Can't figure out why and can't see any error in the SQL.
//////////////////////////////////////////////
// FIND ANY ORDERS THAT WERE MARKED AS DELIVERED
// BUT HAVE NOT BEEN MADE ACTIVE IN SQUID OR OPENVPN TABLES
//////////////////////////////////////////////
$db_selected = mysql_select_db("AAAAA", $squid_conn_int);
if (!$db_selected) {
mail('AAAAA@AAAAA.co.uk', 'IntegrityCheck script error', mysql_error().' error');
die ('Can\'t use database: ' . mysql_error());
}
$result = mysql_query("
SELECT orders.orders_id , orders.customers_id , orders.customers_name , orders.customers_email_address , orders.payment_method , orders.last_modified ,
orders.orders_status , orders_products.products_id, products_description.products_name
FROM orders
INNER JOIN orders_products ON orders_products.orders_id = orders.orders_id
INNER JOIN products_description ON products_description.products_id = orders_products.products_id
WHERE orders_status =3
AND last_modified > NOW( ) - INTERVAL 120 MINUTE
ORDER BY orders_id DESC" , $squid_conn_int
);
if (mysql_num_rows($result) > 0) {
while ($box = mysql_fetch_array($result, MYSQL_ASSOC)) {
//if found, take order ID and products id
$oid = $box['orders.orders_id'];
$custid = $box['orders.customers_id'];
$prodid = $box['orders_products.products_id'];
//if proxy, check if active in squid
mysql_select_db("squid", $squid_conn_remote);
if (!$db_selected) {
mail('AAAAA@AAAAA.co.uk', 'IntegrityCheck script error', mysql_error().' error');
die ('Can\'t use database: ' . mysql_error());
}
if ($prodid == 31 ||
$prodid == 28 ||
$prodid == 29 ||
$prodid == 34 ||
$prodid == 40 ||
$prodid == 32)
{
$newresult = mysql_query('SELECT customers_id FROM passwd WHERE customers_id = '.$custid.' AND enabled = 0 AND UpdateOnNextCycle = 0', $squid_conn_remote)
or die (mysql_error());
}
mysql_select_db("squid", $squid_conn_remote);
if ($prodid == 37 ||
$prodid == 38 )
{
$newresult = mysql_query('SELECT customers_id FROM OpenVPN WHERE customers_id = '.$custid.' AND enabled = 0 AND UpdateOnNextCycle = 0', $squid_conn_remote)
or die (mysql_error());
}
if (mysql_num_rows($newresult) == 0) {
//if not active in squid or VPN then connect to OSC database
//delete anything in orders status history with 1
//change status in orders to 1
$db_selected = mysql_select_db("AAAAA", $squid_conn_int);
if (!$db_selected) {
mail('AAAAA@AAAAA.co.uk', 'IntegrityCheck script error', mysql_error().' error');
die ('Can\'t use database: ' . mysql_error());
}
mysql_query("DELETE FROM orders_status_history WHERE orders_id = ".$oid." AND customer_notified = 1", $squid_conn_int)
or die (mysql_error());
mysql_query("UPDATE orders SET orders_status = 1 WHERE orders_id = ".$oid, $squid_conn_int)
or die (mysql_error());
//these orders will now be picked up by the next IntegrityCheck run in the top part of this script
}
}
}