Page 1 of 1

Cron jobs not working after changing hosting provider

Posted: Mon Sep 26, 2022 9:46 pm
by VanioBoy
[SOLVED]
Hi,

I have the following problem after changing the hosting provider.
Cron jobs are not running.
After a lot of searching, I found that the php version of the database is newer. I tried options but it didn't work.

I am posting the code that needs to connect to the database.

Code: Select all

header('Content-Type: text/html; charset=utf-8');
ini_set('max_execution_time', '1200');
ini_set('memory_limit', '128M');

require_once('/home/***/public_html/config.php');

mysql_connect(DB_HOSTNAME,DB_USERNAME,DB_PASSWORD) or die ("Unable to connect to MySQL");
mysql_select_db(DB_DATABASE) or die ("I can't select the base");
mysql_query("SET NAMES 'utf8'") or die("I cannot complete the request");

$query = "SELECT sku, quantity, stock_status_id, price FROM oc_product"; 
$result = mysql_query($query) or die("Data not found.");
How do I get this code to work with php 7+
Opencart 2.3.0.2

Re: Cron jobs not working after changing hosting provider

Posted: Tue Sep 27, 2022 5:28 pm
by ADD Creative
You need to change the mysql_ functions to mysqli_. However you can't just rename them as the parameters are different. You will need to pass the mysql object return by mysqli_connect to each mysqli_query.

It will be something like this (note: not tested).

Code: Select all

$link = mysqli_connect(DB_HOSTNAME,DB_USERNAME,DB_PASSWORD,DB_DATABASE) or die ("Unable to connect to MySQL");
mysqli_set_charset($link, "utf8") or die("I cannot complete the request");

$query = "SELECT sku, quantity, stock_status_id, price FROM oc_product"; 
$result = mysqli_query($link, $query) or die("Data not found.");

Re: Cron jobs not working after changing hosting provider

Posted: Tue Sep 27, 2022 7:08 pm
by paulfeakins
VanioBoy wrote:
Mon Sep 26, 2022 9:46 pm
After a lot of searching, I found that the php version of the database is newer. I tried options but it didn't work.
Well the database doesn't have a PHP version, it probably has a MySQL version.

You could get a developer to re-write that for you.

Re: Cron jobs not working after changing hosting provider

Posted: Tue Sep 27, 2022 8:05 pm
by VanioBoy
Thanks :) , but I have one more problem.
This code should update a product's price and availability, but it doesn't. Can I help a little more?

Code: Select all

if($price != $products[(string)$product[0]['codeId']]['price'] or $stock_status_id != $products[(string)$product[0]['codeId']]['stock_status_id'] or $quantity != $products[(string)$product[0]['codeId']]['quantity']){
$query8 = "update oc_product set `quantity`='$quantity',`stock_status_id`='$stock_status_id',`price`='$price' where sku='".(string)$product[0]['codeId']."' limit 1" ; 
mysqli_query($link, $query8);   
}

Re: Cron jobs not working after changing hosting provider

Posted: Tue Sep 27, 2022 11:28 pm
by ADD Creative
Anything in your PHP error log (check it's enabled first)?

Re: Cron jobs not working after changing hosting provider

Posted: Wed Sep 28, 2022 3:53 pm
by VanioBoy
ADD Creative wrote:
Tue Sep 27, 2022 11:28 pm
Anything in your PHP error log (check it's enabled first)?
No errors related to cron tasks.

Re: Cron jobs not working after changing hosting provider

Posted: Wed Sep 28, 2022 6:53 pm
by ADD Creative
The issue could be anyway. You would need to check the code at every step to make sure it's connecting to the database and receiving the correct data, etc.

Re: Cron jobs not working after changing hosting provider

Posted: Wed Sep 28, 2022 7:33 pm
by VanioBoy
ADD Creative wrote:
Wed Sep 28, 2022 6:53 pm
The issue could be anyway. You would need to check the code at every step to make sure it's connecting to the database and receiving the correct data, etc.
I added error checking codes, they don't detect anything.
I think the problem lies in this part of when:

Code: Select all

					if(isset($products[(string)$product[0]['codeId']])){
						if($price != $products[(string)$product[0]['codeId']]['price'] or $stock_status_id != $products[(string)$product[0]['codeId']]['stock_status_id'] or $quantity != $products[(string)$product[0]['codeId']]['quantity']){
						    $query8 = "update oc_product set `quantity`='$quantity',`stock_status_id`='$stock_status_id',`price`='$price' where sku='".(string)$product[0]['codeId']."' limit 1" ;
							mysqli_query($con, $query8);

Re: Cron jobs not working after changing hosting provider

Posted: Wed Sep 28, 2022 7:54 pm
by ADD Creative
Log your $query8 and check the SQL looks correct. You could even run the SQL in phpMyAdmin to see if it works.

If you need a developer to look at it. You could post a request in the Commercial Support forum. viewforum.php?f=88

Re: Cron jobs not working after changing hosting provider

Posted: Wed Sep 28, 2022 8:38 pm
by VanioBoy
ADD Creative wrote:
Wed Sep 28, 2022 7:54 pm
Log your $query8 and check the SQL looks correct. You could even run the SQL in phpMyAdmin to see if it works.

If you need a developer to look at it. You could post a request in the Commercial Support forum. viewforum.php?f=88
Thank you for your time.

Re: Cron jobs not working after changing hosting provider

Posted: Wed Sep 28, 2022 11:21 pm
by straightlight
VanioBoy wrote:
Wed Sep 28, 2022 8:38 pm
ADD Creative wrote:
Wed Sep 28, 2022 7:54 pm
Log your $query8 and check the SQL looks correct. You could even run the SQL in phpMyAdmin to see if it works.

If you need a developer to look at it. You could post a request in the Commercial Support forum. viewforum.php?f=88
Thank you for your time.
Now that the issue has been resolved, please add: [SOLVED] at the beginning of the subject line on your first post.