Welcome to the Cumulus Support forum.

Latest Cumulus MX V3 release 3.28.6 (build 3283) - 21 March 2024

Cumulus MX V4 beta test release 4.0.0 (build 4017) - 17 March 2024

Legacy Cumulus 1 release v1.9.4 (build 1099) - 28 November 2014 (a patch is available for 1.9.4 build 1099 that extends the date range of drop-down menus to 2030)

Download the Software (Cumulus MX / Cumulus 1 and other related items) from the Wiki

Update to PHP 7.1 some scripts not working

Other discussion about creating web sites for Cumulus that doesn't have a specific subforum

Moderator: daj

Post Reply
User avatar
PaulMy
Posts: 3775
Joined: Sun 28 Sep 2008 11:54 pm
Weather Station: Davis VP2 Plus 24-Hour FARS
Operating System: Windows8 and Windows10
Location: Komoka, ON Canada
Contact:

Update to PHP 7.1 some scripts not working

Post by PaulMy »

I have previously read some of the posts on PHP 7.x updates but not paid a lot of attention.
I had been using PHP v.5.6 and today decided to try v.7.1 and some scripts are no longer working.
http://www.komokaweather.ca/wxhistorical-colour1.php
http://www.komokaweather.ca/betel_datasummary.php
http://www.komokaweather.com/mysql/monthly-temp.php
http://www.komokaweather.com/mysql/monthly-data.php

There may be more not working but these are the first I found.
What do I look for to see what code is at fault, and how to correct?

Thanks for any help and guidance.
Paul
Davis Vantage Pro2+
C1 www.komokaweather.com/komokaweather-ca
MX www.komokaweather.com/cumulusmx/index.htm /index.html /index.php
MX www.komokaweather.com/cumulusmxwll/index.htm /index.html /index.php
MX www. komokaweather.com/cumulusmx4/index.htm

Image
User avatar
ConligWX
Posts: 1570
Joined: Mon 19 May 2014 10:45 pm
Weather Station: Davis vPro2+ w/DFARS + AirLink
Operating System: Ubuntu 22.04 LTS
Location: Bangor, NI
Contact:

Re: Update to PHP 7.1 some scripts not working

Post by ConligWX »

Firstly check your apache error logs, they should give a definition of the error.
Regards Simon

https://www.conligwx.org - @conligwx
Davis Vantage Pro2 Plus with Daytime FARS • WeatherLink Live • Davis AirLink • PurpleAir •

Image
User avatar
saratogaWX
Posts: 1170
Joined: Wed 06 May 2009 5:02 am
Weather Station: Davis Vantage Pro Plus
Operating System: Windows 10 Professional
Location: Saratoga, CA, USA
Contact:

Re: Update to PHP 7.1 some scripts not working

Post by saratogaWX »

From the PHP.net website
PHP 5 users can choose between the deprecated mysql extension, mysqli, or PDO_MySQL. PHP 7 removes the mysql extension, leaving only the latter two options.
If your programs are running mysql calls, they'll have to be converted to mysqli calls to run on PHP7+

You might tryhttps://www.phpclasses.org/blog/package/9199/po ... ml#convert for some help in doing the conversions mysql->mysqli
User avatar
PaulMy
Posts: 3775
Joined: Sun 28 Sep 2008 11:54 pm
Weather Station: Davis VP2 Plus 24-Hour FARS
Operating System: Windows8 and Windows10
Location: Komoka, ON Canada
Contact:

Re: Update to PHP 7.1 some scripts not working

Post by PaulMy »

Thanks Simon and Ken,
This may be larger than I can handle but will start and make an effort... and hopefully learn from it.

The monthly_temp.php and monthly-data.php scripts both start with the same lines 1 through 37 which includes

Code: Select all

<?php 

		//include the information needed for the connection to MySQL data base server. This file contains the databasename,hostname, usernme, and password. For an alternative method:http://php.about.com/od/phpwithmysql/qt/connect_sql_php.htm or google connect to mysql using php 
		include ("dbconfig.php");
		// require_once("cumuluswebtags.php");


		// connect to the MySQL database server 
		$db = mysql_connect($dbhost, $dbuser, $dbpassword) or die("Connection Error: " . mysql_error()); 
		 
		 
		// select the database 
		mysql_select_db($database) or die("Error connecting to db."); 
I have looked at the tutorial link Ken provided and presume if I make these changes
Script line 32: // connect to the MySQL database server
Existing line 33: $db = mysql_connect($dbhost, $dbuser, $dbpassword) or die("Connection Error: " . mysql_error());
Modify line 33: $db = mysqli_connect($dbhost, $dbuser, $dbpassword) or die("Connection Error: " . mysqli_connect_error());
Tutorial example old: $connection = mysql_connect( 'host', 'username', 'password', new_link,flags);
Tutorial example new: $connection = mysqli_connect( 'host', 'username', 'password', 'database', 'port', 'socket');

Script line 36: // select the database
Existing line 37: mysql_select_db($database) or die("Error connecting to db.");
Modify line 37: mysqli_select_db($database) or die("Error connecting to db.");
Tutorial example old: $database = mysql_select_db( 'database', $link);
Tutorial example new: $database = mysqli_select_db($link, 'database');
Further the scripts have somewhat similar code for getting the data

Code: Select all

	// the actual query for the grid data 
		$SQL = "SELECT LogDate,  Year(LogDate) as Year, maxtemp, max(IF(month(logdate)=1, maxtemp,null)) as January, max(IF(month(logdate)=2, maxtemp,null))as February, max(IF(month(logdate)=3, maxtemp,null))as March, max(IF(month(logdate)=4, maxtemp,null))as April, max(IF(month(logdate)=5, maxtemp,null))as May, max(IF(month(logdate)=6, maxtemp,null))as June, max(IF(month(logdate)=7, maxtemp,null))as July, max(IF(month(logdate)=8, maxtemp,null))as August ,max(IF(month(logdate)=9, maxtemp,null))as September,max(IF(month(logdate)=10, maxtemp,null))as October, max(IF(month(logdate)=11, maxtemp,null))as November, max(IF(month(logdate)=12, maxtemp,null))as December, max(maxtemp) as total FROM Dayfile  group by year";
		$resultmaxtemp = mysql_query($SQL)or die('Error: ' . mysql_error()); 

		$SQL = "SELECT LogDate,  Year(LogDate) as Year, avgtemp, round(avg(IF(month(logdate)=1, avgtemp,null)),1) as January, round(avg(IF(month(logdate)=2, avgtemp,null)),1)as February, round(avg(IF(month(logdate)=3, avgtemp,null)),1) as March, round(avg(IF(month(logdate)=4, avgtemp,null)),1)as April, round(avg(IF(month(logdate)=5, avgtemp,null)),1)as May, round(avg(IF(month(logdate)=6, avgtemp,null)),1)as June, round(avg(IF(month(logdate)=7, avgtemp,null)),1)as July, round(avg(IF(month(logdate)=8, avgtemp,null)),1)as August, round(avg(IF(month(logdate)=9, avgtemp,null)),1) as September, round(avg(IF(month(logdate)=10, avgtemp,null)),1) as October, round(avg(IF(month(logdate)=11, avgtemp,null)),1) as November, round(avg(IF(month(logdate)=12, avgtemp,null)),1)as December, round(avg(avgtemp),1) as total FROM Dayfile group by year";
		$resultavgtemp = mysql_query($SQL)or die('Error: ' . mysql_error()); 

etc....
and presume I can replace all the occurrences of mysql_select, mysql_query, mysql_fetch and mysql_error with mysqli_select, mysqli_query, mysqli_fetch and mysqli_connect_error.

Before I start to make those changes does that appear to be correct?

Thanks for your patience and guidance,
Paul
Davis Vantage Pro2+
C1 www.komokaweather.com/komokaweather-ca
MX www.komokaweather.com/cumulusmx/index.htm /index.html /index.php
MX www.komokaweather.com/cumulusmxwll/index.htm /index.html /index.php
MX www. komokaweather.com/cumulusmx4/index.htm

Image
User avatar
saratogaWX
Posts: 1170
Joined: Wed 06 May 2009 5:02 am
Weather Station: Davis Vantage Pro Plus
Operating System: Windows 10 Professional
Location: Saratoga, CA, USA
Contact:

Re: Update to PHP 7.1 some scripts not working

Post by saratogaWX »

Alas, I am not an expert in using SQL (nor do I have it currently running on my weather website), so far be it from me to counsel you on the conversion.
Others, with more experience, will need to give that advice...
sfws
Posts: 1183
Joined: Fri 27 Jul 2012 11:29 am
Weather Station: Chas O, Maplin N96FY, N25FR
Operating System: rPi 3B+ with Buster (full)

Re: Update to PHP 7.1 some scripts not working

Post by sfws »

PaulMy wrote:Further the scripts have somewhat similar code for getting the data
Paul - the right hand side of various "$SQL=" retrievals are indeed pure SQL instructions and therefore unaffected by you changing PHP version.
PaulMy wrote:presume I can replace all the occurrences of mysql_select, mysql_query, mysql_fetch and mysql_error with mysqli_select, mysqli_query, mysqli_fetch and mysqli_connect_error.
I don't know the specific scripts that you are using, so the following comments are based on my limited PHP experience with updating other scripts.

To the best of my knowledge, the parameters for 'mysqli' are mostly the same as for the obsolete 'mysql' , so indeed a global replacement that swaps the former for the latter should work in the majority of cases. However, as you have already noticed, the parameters are in a different order for selecting the database! However, I would use an alternative syntax if it was my code, replacing

Code: Select all

mysql_query
with

Code: Select all

$mysqli->query
My alternative for your lines 33 to 37 in one instruction is

Code: Select all

$db = new mysqli($dbhost, $dbuser, $dbpassword, $database) or die("Connection Error: " . mysqli_error());
The error message that this outputs will say whether the error is in the connection parameters or in finding the database, so you don't need two separate stages as per original.

Notepad++ (that I have just been using for this functionality in a non database context) has "replace in all open files" (start in its search menu), and similar functionality is available in some other editors.

[Post edit - I accidentally typed 'mysql' instead of 'mysqli' in my code example - sorry about that]
Last edited by sfws on Thu 12 Apr 2018 7:52 am, edited 2 times in total.
User avatar
BeaumarisWX
Posts: 357
Joined: Mon 09 Apr 2012 2:38 pm
Weather Station: Davis VP2 Plus - 24hr FARS
Operating System: Windows 10 Pro Hades Canyon
Location: Beaumaris, Tasmania, AU
Contact:

Re: Update to PHP 7.1 some scripts not working

Post by BeaumarisWX »

Hi Paul,
Sent you PM, hope it helps. Sorry no time for more help :cry: .
Kind regards,
Tony Beaumaris, Tasmania (AUS)

CMX Mobile : https://beaumaris-weather.com/BWX/
CMX Default: https://beaumaris-weather.com/cumulusmx_default/
Colour Dashboard : https://beaumaris-weather.com/dashborad_color.php
Click below for Saratoga Template :
Image
Post Reply