функция — PHP фатальная ошибка: вызов неопределенного метода

Здесь я импортирую класс files.class.php, который содержит функцию getAllFiles ():

include_once('lib/files.class.php');

Здесь я вызываю функцию:

<?php
$files = new Files($db);
$jsonEncoding = json_encode($files->getAllFiles());
$jsonFile = fopen("jsonEncoded.json", "w") or die ("Unable to open file!");
fwrite($jsonFile, $jsonEncoding);
$contentOfFile = file_get_contents('./jsonEncoded.json');
echo $contentOfFile;
fclose($jsonFile);
?>

Это функция getAllFiles ():

public function getAllFiles() {
if (!($stmt = $this->connection->prepare("SELECT ID, Latitude, Longitude, Name, Radius FROM Files"))) {
$this->lastError = 'Failed to prepare query: ('.$this->connection->errno.') '.$this->connection->error;
return false;
} else {
// Execute the query and store the result set
$stmt->execute();
$stmt->store_result();

// Bind the results to variables
$stmt->bind_result($id, $latitude, $longitude, $name, $radius);
$results = array();
// Keep fetching rows
while ($stmt->fetch()) {
// Add to array
$results[] = array(
'ID' => $id,
'Latitude' => $latitude,
'Longitude' => $longitude,
'Name' => $name,
'Radius' => $radius,
);
}
// Return the results array
return $results;
}
}

Я получаю следующую ошибку:

Неустранимая ошибка: вызов неопределенного метода Files :: getAllFiles () в /var/www/localhost/htdocs/mbax4cl3/groupproject/map.php в строке 83

Спасибо !

1

Решение

Даже если это не имеет никакого смысла, похоже, проблема в коде после этой строки: $ jsonEncoding = json_encode ($ files-> getAllFiles ());
Однако ошибка возникает в этой строке.

Я изменил код на следующий, и он отлично работает:

    <?php
$files = new Files($db);
$jsonEncoding = json_encode($files->getAllFiles());
print_r($jsonEncoding);
?>

Спасибо !

0

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector