A
A
Anastasia2020-04-26 18:14:39
PHP
Anastasia, 2020-04-26 18:14:39

Why does $bd = $row[0] return null while just $row[0] returns data?

Hello. Everything is somehow very illogical ...
The situation is this. Through cUrl, I receive data not from my server and check with the data on my own. If there are changes, then I write these records to my database. If there are no changes, then I get the previous record and display the changes.

$stmt = $pdo->prepare('SELECT * FROM bd ORDER BY id DESC LIMIT 2;');
$stmt->execute();
$row = $stmt->fetchAll();

$data = json_encode($formData);
$ch = curl_init("https://local.server/api/personal/result?data=$data");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Accept: application/json']);
$result = curl_exec($ch);
if (curl_errno($ch)) $curlerror = 'Ошибка в запросе 2:' . curl_error($ch);
curl_close($ch);

$array = json_decode($result); // Декодируем ответ
$f_arr_person = $array->data; // Получаем статус обработки

for ($i = 0, $size2 = count($f_arr_person); $i < $size2; ++$i) { 
$f_str_person = implode("|", (array)$f_arr_person[$i]); 
}

if ($f_str_person != $row[0]['data']) {
    $sql = 'INSERT INTO bd (data) VALUES (:data)';
    $query = $pdo -> prepare($sql);
    $query -> execute(['data' => $f_str_person]);
    $bd_last = $row[0];
} else {
    $bd_last = $row[1];
}
$from["qqq"][] = ["Дата"=>$row[0]["Date"]];
$from["qqq"][] = $f_arr_person;
echo json_encode($from);


So, when I try to get data for myself via ajax, for some reason it doesn’t work like this: But it works like this: I tried to put a variable here: $row[ 0 ], but it didn’t work for me either ...
$from["qqq"][] = "Дата"=>$bd_last["Date"];
$from["qqq"][] = "Дата"=>$row[0]["Date"];

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anastasia, 2020-04-29
@nastya97core

it was a stupid mistake. solved
$stmt = $pdo->prepare('SELECT * FROM bd ORDER BY id DESC LIMIT 2 ;');

A
AUser0, 2020-04-26
@AUser0

So you have this $row[0]['data']and that $row[0]["Date"].
For PHP, these are two completely different things.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question