显示下拉菜单

PDOStatement::fetch()

« PDOStatement::execute | PDOStatement::fetchAll »
<?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
);

$mixed $pdostatement->fetch (
    
?// [int $fetch_style]
    
?// [int $cursor_orientation = PDO::FETCH_ORI_NEXT]
    
  // [int $cursor_offset = 0]
);
?>
结果
$pdo = 'PDO instance'
$int = 7
$pdostatement = 'PDOStatement instance'
$bool = true
$mixed = (object) [
   
'NAME' => 'apple',
   
'COLOUR' => 'red',
   
'CALORIES' => '150',
]
示例
#1 PDOStatement::fetch  (/* $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" */
 
PDO::FETCH_ASSOC)
#2 PDOStatement::fetch  (/* $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" */
 
PDO::FETCH_BOTH)
#3 PDOStatement::fetch  (/* $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" */
 /* $driver_options = [PDO::ATTR_CASE => PDO::CASE_UPPER] */
 
PDO::FETCH_OBJ)
#4 PDOStatement::fetch  (/* $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 WHERE calories <= :calories AND colour = :colour" */
 /* $input_parameters = [":calories" => 150, ":colour" => "red"] */
 
PDO::FETCH_ASSOC)
#5 PDOStatement::fetch  (/* $exec_statement = "CREATE TABLE fruit (name, colour, calories INT); INSERT INTO fruit VALUES ('apple', 'red', 150)" */
 /* $statement = "SELECT name, colour, calories FROM fruit WHERE calories 150 AND colour = 'red'" */
 /* $driver_options = [PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL] */
)
另请参阅
PDO::exec, PDO::prepare, PDOStatement::execute, PDOStatement::fetchAll, PDOStatement::fetchColumn, PDOStatement::fetchObject