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 4019) - 03 April 2024

Legacy Cumulus 1 release 1.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

mysqli transition

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

Moderator: daj

Post Reply
User avatar
laulau
Posts: 678
Joined: Tue 13 Oct 2009 10:52 pm
Weather Station: WeatherDuino Pro2
Operating System: Win 7
Location: Meyenheim, Alsace, FR
Contact:

mysqli transition

Post by laulau »

Hi,
I'm trying to convert some of my scripts using mysql to mysqli. (it's time :oops: )
I have a problem with a request that works in phpmyadmin but when calling from a php script I have an error:
ERROR - Bad Select Statement: SELECT UNIX_TIMESTAMP(LogDateTime), Temp, Hum FROM AllCdata WHERE LogDateTime > (SELECT MAX(LogDateTime) - INTERVAL 12 day FROM AllCdata) ORDER BY LogDateTime ASC
this query is working with mysql , but isn't with mysqli ! :groan:
Laurent

Image
User avatar
laulau
Posts: 678
Joined: Tue 13 Oct 2009 10:52 pm
Weather Station: WeatherDuino Pro2
Operating System: Win 7
Location: Meyenheim, Alsace, FR
Contact:

Re: mysqli transition

Post by laulau »

Hi,
No SQL Guru ? :( who can tell me where to look :?:
Laurent

Image
User avatar
mcrossley
Posts: 12756
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: mysqli transition

Post by mcrossley »

Perhaps you could post the actual code that sends the command, the SQL statement looks OK to me.
User avatar
laulau
Posts: 678
Joined: Tue 13 Oct 2009 10:52 pm
Weather Station: WeatherDuino Pro2
Operating System: Win 7
Location: Meyenheim, Alsace, FR
Contact:

Re: mysqli transition

Post by laulau »

Hi,
with mysqli not working http://meteo.laurentmey.fr/sqli/monthLo ... p?view=sce
old mysql : http://meteo.laurentmey.fr/sqli/monthLo ... p?view=sce
The basic script is yours ;)
Thanks
Laurent

Image
User avatar
kocher
Posts: 233
Joined: Sat 19 Apr 2014 7:57 pm
Weather Station: Davis Vantage Pro2+
Operating System: Windows 10
Location: San Sebastian - Spain
Contact:

Re: mysqli transition

Post by kocher »

Good morning Laurent

I think for the modification to work you must also modify the connection file:

As an example I put two connection files to the same database, but one is mysql and the other is mysqli:

1): mysql

Code: Select all

<?php
$server ="your server";
$user="user";
$pass="your password";
$db="your database";
mysql_connect($server,$user,$pass) or die ("Erreur SQL : ".mysql_error() );
mysql_select_db($db) or die ("Erreur SQL : ".mysql_error() );
?>
2): mysqli

Code: Select all

<?php
$server ="your server;
$user = "user";
$pwd = "your password";
$db ="your database";
$conn=mysqli_connect($server,$user,$pwd,$db);
If(! $conn) {
exit("Echec de la connexion");
}
?>
Then you have to check that this connection file works correctly.
Image
User avatar
laulau
Posts: 678
Joined: Tue 13 Oct 2009 10:52 pm
Weather Station: WeatherDuino Pro2
Operating System: Win 7
Location: Meyenheim, Alsace, FR
Contact:

Re: mysqli transition

Post by laulau »

I don't understand.
I have the script to insert the realtime.txt in realtime database working well with mysqli !
begin: Running from web server
Script start: 19/03/20 - 14:29:26
Importing file: ../../cm1/realtime.txt, To table: Realtime ...
Connected to database OK.
Set MySQL TZ OK.
Processing realtime file...
Target table already exists.
Prepared SQL statement OK.
Inserting data...
Data insert done, 1 rows inserted
Deleting old realtime records...
done. Deleted 1 old rows.
Script complete: 19/03/20 - 14:29:26
Execution time: 0 secs
end
Laurent

Image
Mapantz
Posts: 1809
Joined: Sat 17 Dec 2011 11:55 am
Weather Station: Davis Vantage Pro2
Operating System: Windows 11 x64
Location: Dorset - UK
Contact:

Re: mysqli transition

Post by Mapantz »

I don't have time to check what's different, but i've uploaded the one I use.

It works fine on the latest version of PHP.
realtimeLogSql.txt
You do not have the required permissions to view the files attached to this post.
Image
User avatar
mcrossley
Posts: 12756
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: mysqli transition

Post by mcrossley »

:? It is essentially the same as my current version of that script that I use on my home page - the resulting SQL query is the same, and it is working with mysqli for me?

I'm currently using MariaDB 10.1
User avatar
mcrossley
Posts: 12756
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: mysqli transition

Post by mcrossley »

Ah! You are not connecting to a database, you just connect to the server. So like kocher said above. You have...

Code: Select all

// Connect to the datbase
$mysqli = new mysqli($dbhost, $dbuser, $dbpassword);
if ($mysqli->connect_errno) {
	die('Failed to connect to the database server');
}
But then no database connect. I do it one call like this...

Code: Select all

// Connect to the datbase
$mysqli = new mysqli($dbhost, $dbuser, $dbpassword, $database);
if ($mysqli->connect_errno) {
	die('Failed to connect to the database server');
}
User avatar
laulau
Posts: 678
Joined: Tue 13 Oct 2009 10:52 pm
Weather Station: WeatherDuino Pro2
Operating System: Win 7
Location: Meyenheim, Alsace, FR
Contact:

Re: mysqli transition

Post by laulau »

Thanks
I don't see that $database was missing ! :bash:
Laurent

Image
Post Reply