Mostrar lista de opciones

PDOStatement::fetchColumn()

« PDOStatement::fetchAll | PDOStatement::fetchObject »
<?php
$pdo 
= new PDO("sqlite::memory:"nullnull, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
$int $pdo->exec(
    
  // string $exec_statement
);

$pdostatement $pdo->prepare(
    
// string $statement,
    
 // array $driver_options = array()
);

$bool $pdostatement->execute(
    
  // array $input_parameters
);

$string $pdostatement->fetchColumn (
    
  // [int $column_number = 0]
);
?>
Resultado
$pdo = 'PDO instance'
$int = 7
$pdostatement = 'PDOStatement instance'
$bool = true
$string = 'apple'
Ejemplos
#1 PDOStatement::fetchColumn  (/* $exec_statement = "CREATE TABLE fruit (name, colour, calories INT); INSERT INTO fruit VALUES ('apple', 'red', 150), ('banana', 'yellow', 250), ('kiwi', 'brown', 75), ('lemon', 'yellow', 25), ('orange', 'orange', 300), ('pear', 'green', 150), ('watermelon', 'pink', 90)" */
 /* $statement = "SELECT name, colour, calories FROM fruit" */
)
#2 PDOStatement::fetchColumn  (/* $exec_statement = "CREATE TABLE fruit (name, colour, calories INT); INSERT INTO fruit VALUES ('apple', 'red', 150), ('banana', 'yellow', 250), ('kiwi', 'brown', 75), ('lemon', 'yellow', 25), ('orange', 'orange', 300), ('pear', 'green', 150), ('watermelon', 'pink', 90)" */
 /* $statement = "SELECT name, colour, calories FROM fruit" */
 
1)
Ver también
PDO::exec, PDO::prepare, PDO::query, PDOStatement::execute, PDOStatement::fetch, PDOStatement::fetchAll