Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Need to change pdo fetching mode

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

[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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading