我想知道为什么您可以在执行查询之前和之后设置提取模式,结果仍然使用给定的提取模式......?
这意味着 PDO 从数据库服务器检索查询结果作为数字和关联?唔...
是否只能检索一个..?数字结果还是关联结果?
这两个示例返回完全相同的结果。如果我setFetchMode
省略了数字和 assoc 结果被打印
执行前
$sth = $dbh->prepare("SELECT REFERENCED_TABLE_NAME table_name, REFERENCED_COLUMN_NAME column_name\n"
."FROM KEY_COLUMN_USAGE\n"
."WHERE REFERENCED_TABLE_NAME IS NOT NULL && REFERENCED_COLUMN_NAME IS NOT NULL\n"
."GROUP BY REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME");
$sth->setFetchMode(PDO::FETCH_ASSOC);
$sth->execute();
echo '<pre>';
foreach($sth as $row){
print_r($row);
}
echo '</pre>';
执行后
$sth = $dbh->prepare("SELECT REFERENCED_TABLE_NAME table_name, REFERENCED_COLUMN_NAME column_name\n"
."FROM KEY_COLUMN_USAGE\n"
."WHERE REFERENCED_TABLE_NAME IS NOT NULL && REFERENCED_COLUMN_NAME IS NOT NULL\n"
."GROUP BY REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME");
$sth->execute();
$sth->setFetchMode(PDO::FETCH_ASSOC);
echo '<pre>';
foreach($sth as $row){
print_r($row);
}
echo '</pre>';