(03-18-2023, 06:10 PM)Rob F Wrote: That's I'll check that out.
This is the version I have. Does it match up with yours?
PHP 7.3.31-1~deb10u1 (cli) (built: Oct 24 2021 15:18:08) ( NTS )
100% those queries were working for a lot of people including myself as some of them have been there basically from day 1. It's obvious just from forum posts, guaranteed people using it didn't make all the changes you did. I'm really hoping I can find out why this is the case, I'm hoping you have a different PHP version but if you used my install script then I can't see how yours would be different.
What do you think of this updated php code vs what I'm currently doing?
Switched from mysqli to PDO to access the database, using prepared statement so it's safer, try catch block and error handling.
This file is the new dcGetPorts.php
PHP Code:<?php
header('Content-Type: application/json');
header("Access-Control-Allow-Origin: *");
try {
require '../php/database.php';
$query = "SELECT `dcSortID` FROM `systemSettings` WHERE `userID` = 1";
$stmt = $pdo->prepare($query);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$sortID = $row['dcSortID'];
if ($sortID == 1) {
$s = "name";
} else if ($sortID == 2) {
$s = "iconID";
} else if ($sortID == 3) {
$s = "gpio";
}
$query = "SELECT `pinID`, `gpio`, `assigned`, `name`, `iconID`, `invert`, `manual` FROM `pinsAvailable` WHERE `pinTypeID` = 2 AND `assigned` = 1 ORDER BY `$s` ASC";
$stmt = $pdo->prepare($query);
$stmt->execute();
$dataWindow = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo json_encode($dataWindow);
} catch (PDOException $e) {
echo "Error: " . $e->getMessage();
}
$pdo = null;
Mine is different:
Code:
$ php -v
PHP 7.4.33 (cli) (built: Nov 8 2022 11:40:37) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.33, Copyright (c), by Zend Technologies
Which Debian do you have in your Pi ? Probaby not the 11:
Code:
$ cat /etc/debian_version
11.6
the code above looks good to me
It should work anyway, but triggering a huge warning:
Code:
$ php -r "echo 'HELLO '.World.'';"
PHP Warning: Use of undefined constant World - assumed 'World' (this will throw an Error in a future version of PHP) in Command line code on line 1
HELLO World
in php8 this this is fixed and the undefined constant is not considered a string anymore.
Probably on some environment this didn't worked because the error is outputting some unxepceted data (the error message) that break the AJAX call if you expect a json or something similar.