I have a table with two columns. Table: ctgtable and columns: id and ctg . Since I am completely moving from previous mysql_* to PDO , I encounter some doolish errors (or possibly a lack of knowledge).
Question
I want to select the entire ctg column (no more than 20 rows in total) into an array with integer indices.
My method
The closest possible solution, in my opinion, was the following:
<?php $sth = $dbh->prepare("SELECT id, ctg FROM ctgtable"); $sth->execute(); $result = $sth->fetchAll(PDO::FETCH_COLUMN, 1); var_dump($result); ?>
Is there any other shorter / better alternative for the same result? Or is this the best / only possible method to get the results.
Sample table
id ctg 01 movie 27 tv 64 sports
and etc.
Result Example
Array( 1 => "tv", 2 => "movie", 3 => "anime", 4 => "game", 5 => "telugu" );
Indexing may or may not start at 0. This does not matter to me. I tried to find such a possible question, but none of them was relevant to my question.
source share