Using PHP PDO and psql
My query:
$stmt = $this->pdo->prepare("select distinct extract(year from conclusion) from agreements_register where conclusion is not null");
$stmt->execute();
return $stmt->fetchAll();
it returns this:
[['date_part' => 2021],['date_part' => 2022]]
but I need this:
[2021, 2022]
>Solution :
this is example:
<?php
$sth = $dbh->prepare("SELECT name, colour FROM fruit");
$sth->execute();
$result = $sth->fetchAll(PDO::FETCH_COLUMN, 0);
var_dump($result);
?>
and it will output
Array(3)
(
[0] =>
string(5) => apple
[1] =>
string(4) => pear
[2] =>
string(10) => watermelon
)
and detail you can read this doc:
https://www.php.net/manual/en/pdostatement.fetchall.php
i hope it works for you