This article mainly introduces the output results of various parameters in PHPPDOfetch mode. The purpose of this article is to easily select different parameters based on actual needs, so that you do not need to test them one by one. For more information, see
This article mainly introduces the output results of various parameters in the php pdo fetch mode. The purpose of this article is to easily select different parameters based on actual needs, so that you do not need to test them one by one. For more information, see
The fetch mode function of PDO is too convenient, but it is too troublesome to try to generate the desired results every time. The possible combinations are listed here.
The Code is as follows:
<? Php
$ DbAdapter = new PDO ("mysql: host = localhost; dbname = test", "root", "1234 ");
$ DbAdapter-> exec ("set names 'utf8 ';");
$ Data = $ dbAdapter-> query ("
SELECT id, name, method FROM category
")-> FetchAll (PDO: FETCH_ASSOC );
// Var_dump ($ data );
/*
Array (
Array (
'Id' => '1 ',
'Name' => 'hbo ',
'Method' => 'service ',
),
Array (
'Id' => '2 ',
'Name' => 'new this week ',
'Method' => 'movie ',
),
Array (
'Id' => '3 ',
'Name' => 'playing In replaying ',
'Method' => 'movie ',
),
)
*/
$ Data = $ dbAdapter-> query ("
SELECT name, method FROM category
")-> FetchAll (PDO: FETCH_COLUMN );
// Var_dump ($ data );
/*
Array (
'Hbo ',
'New this week ',
'Hot ining ',
)
*/
$ Data = $ dbAdapter-> query ("
SELECT id, name, method FROM category
")-> FetchAll (PDO: FETCH_UNIQUE | PDO: FETCH_ASSOC );
// Var_dump ($ data );
/*
Array (
'1' => array (
'Name' => 'hbo ',
'Method' => 'service ',
),
'2' => array (
'Name' => 'new this week ',
'Method' => 'movie ',
),
'3' => array (
'Name' => 'playing In replaying ',
'Method' => 'movie ',
),
)
*/
$ Data = $ dbAdapter-> query ("
SELECT method, id, name FROM category
")-> FetchAll (PDO: FETCH_UNIQUE | PDO: FETCH_ASSOC );
// Var_dump ($ data );
/*
Array (
'Service' => array (
'Id' => '1 ',
'Name' => 'hbo ',
),
'Movie '=> array (
'Id' => '3 ',
'Name' => 'playing In replaying ',
),
)
*/
$ Data = $ dbAdapter-> query ("
SELECT id, name, method FROM category
")-> FetchAll (PDO: FETCH_UNIQUE | PDO: FETCH_COLUMN );
// Var_dump ($ data );
/*
Array (
'1' => 'hbo ',
'2' => 'new this week ',
'3' => 'Hit In replaying ',
)
*/
$ Data = $ dbAdapter-> query ("
SELECT method, name, id FROM category
")-> FetchAll (PDO: FETCH_UNIQUE | PDO: FETCH_COLUMN );
// Var_dump ($ data );
/*
Array (
'Service' => 'hbo ',
'Movie '=> 'hot input ',
)
*/
$ Data = $ dbAdapter-> query ("
SELECT method, id, name FROM category
")-> FetchAll (PDO: FETCH_ASSOC | PDO: FETCH_GROUP );
// Var_dump ($ data );
/*
Array (
'Service' => array (
Array (
'Id' => '1'
'Name' => 'hbo'
),
)
'Movie '=> array (
Array (
'Id' => '2'
'Name' => 'new this week'
),
Array (
'Id' => '3'
'Name' => 'Hit In replaying'
),
)
)
*/
$ Data = $ dbAdapter-> query ("
SELECT method, name, id FROM category
")-> FetchAll (PDO: FETCH_GROUP | PDO: FETCH_COLUMN );
// Var_dump ($ data );
/*
Array (
'Service' => array (
'Hbo'
),
'Movie '=> array (
'New this week'
'Hot ining'
),
)
*/
$ Data = $ dbAdapter-> query ("
SELECT id, name, method FROM category
")-> FetchAll (PDO: FETCH_OBJ );
// Var_dump ($ data );
/*
Array (
StdClass {
Public $ id = '1 ';
Public $ name = 'hbo ';
Public $ method = 'service ';
},
StdClass {
Public $ id = '2 ';
Public $ name = 'new this week ';
Public $ method = 'movie ';
},
StdClass {
Public $ id = '3 ';
Public $ name = 'in replaying ';
Public $ method = 'movie ';
},
)
*/
Class Category_1 {}
$ Data = $ dbAdapter-> query ("
SELECT id, name, method FROM category
")-> FetchAll (PDO: FETCH_CLASS | PDO: FETCH_PROPS_LATE," Category_1 ");
// Var_dump ($ data );
/*
Array (
Category_1 {
Public $ id = '1 ';
Public $ name = 'hbo ';
Public $ method = 'service ';
},
Category_1 {
Public $ id = '2 ';
Public $ name = 'new this week ';
Public $ method = 'movie ';
},
Category_1 {
Public $ id = '3 ';
Public $ name = 'in replaying ';
Public $ method = 'movie ';
},
),
*/
Class Category_2 {
Public $ name;
Public $ method;
Public function _ construct (){}
Public function _ set ($ name, $ value ){}
}
$ Data = $ dbAdapter-> query ("
SELECT id, name, method FROM category
")-> FetchAll (PDO: FETCH_CLASS | PDO: FETCH_PROPS_LATE," Category_2 ");
// Var_dump ($ data );
/*
Array (
Category_2 {
Public $ name = 'hbo ';
Public $ method = 'service ';
},
Category_2 {
Public $ name = 'new this week ';
Public $ method = 'movie ';
},
Category_2 {
Public $ name = 'in replaying ';
Public $ method = 'movie ';
},
)
*/
,