Post by VanioBoy » Mon Sep 26, 2022 9:46 pm

[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
Last edited by VanioBoy on Thu Sep 29, 2022 7:24 pm, edited 1 time in total.

New member

Posts

Joined
Wed Nov 09, 2016 5:52 pm


Post by ADD Creative » Tue Sep 27, 2022 5:28 pm

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.");

www.add-creative.co.uk


Expert Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by paulfeakins » Tue Sep 27, 2022 7:08 pm

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.

For quick, professional OpenCart support please email info@antropy.co.uk


User avatar
Guru Member
Online

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - Reigate, Surrey, United Kingdom

Post by VanioBoy » Tue Sep 27, 2022 8:05 pm

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);   
}

New member

Posts

Joined
Wed Nov 09, 2016 5:52 pm


Post by ADD Creative » Tue Sep 27, 2022 11:28 pm

Anything in your PHP error log (check it's enabled first)?

www.add-creative.co.uk


Expert Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by VanioBoy » Wed Sep 28, 2022 3:53 pm

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.

New member

Posts

Joined
Wed Nov 09, 2016 5:52 pm


Post by ADD Creative » 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.

www.add-creative.co.uk


Expert Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by VanioBoy » Wed Sep 28, 2022 7:33 pm

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);

New member

Posts

Joined
Wed Nov 09, 2016 5:52 pm


Post by ADD Creative » 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

www.add-creative.co.uk


Expert Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by VanioBoy » 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.

New member

Posts

Joined
Wed Nov 09, 2016 5:52 pm


Post by straightlight » Wed Sep 28, 2022 11:21 pm

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.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 10 guests