Welcome to the new home of the Cumulus Support forum.

Latest Cumulus release v1.9.4 (build 1099) - 28 November 2014
Latest Cumulus MX release v3.0.0 build 3046 - 02 January 2019. See the Wiki for download

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: 1751
Joined: Sun 28 Sep 2008 11:54 pm
Weather Station: Davis Vantage Pro 2+ w/Envoy USB
Operating System: Windows-8
Location: Komoka, ON Canada
Contact:

Update to PHP 7.1 some scripts not working

Post by PaulMy » Fri 23 Feb 2018 10:24 pm

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

User avatar
ConligWX
Posts: 745
Joined: Mon 19 May 2014 10:45 pm
Weather Station: Davis Vantage Pro2 Plus
Operating System: MeteoBridge Nano SD
Location: Bangor, NI
Contact:

Re: Update to PHP 7.1 some scripts not working

Post by ConligWX » Fri 23 Feb 2018 10:54 pm

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

https://www.conligwx.org
https://twitter.com/conligwx
Davis Vantage Pro2 Plus - Meteobrige Nano SD + Saratoga Templates

User avatar
saratogaWX
Posts: 934
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 » Fri 23 Feb 2018 11:00 pm

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: 1751
Joined: Sun 28 Sep 2008 11:54 pm
Weather Station: Davis Vantage Pro 2+ w/Envoy USB
Operating System: Windows-8
Location: Komoka, ON Canada
Contact:

Re: Update to PHP 7.1 some scripts not working

Post by PaulMy » Sat 24 Feb 2018 1:33 am

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

User avatar
saratogaWX
Posts: 934
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 » Sat 24 Feb 2018 4:47 am

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: 462
Joined: Fri 27 Jul 2012 11:29 am
Weather Station: Final post in top ten topic
Operating System: Tempermental Win. 10 PC
Location: Moving

Re: Update to PHP 7.1 some scripts not working

Post by sfws » Sat 24 Feb 2018 6:46 am

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
HRVistaWeather
Posts: 181
Joined: Mon 09 Apr 2012 2:38 pm
Weather Station: Davis VP2 Plus - 24hr FARS
Operating System: Windows 10 Home (64bit)
Location: Franklin, Huon Valley, Tasmania
Contact:

Re: Update to PHP 7.1 some scripts not working

Post by HRVistaWeather » Sat 24 Feb 2018 6:55 am

Hi Paul,
Sent you PM, hope it helps. Sorry no time for more help :cry: .
Kind regards,
Tony
Huon River Vista - South Franklin Weather - Tasmania
Davis Vantage Pro 2 Plus - FARS, Cumulus MX, 2 Soil Temp/Moist Solar/Rad.
Image

Post Reply