出于某种原因,当我尝试从我的数据库中获取数据时,它会多次返回我的数据。
$base = "mysql:host=" . $config["database"]["host"] . ";port=" . $config["database"]["port"] . ";dbname=" . $config["database"]["name"];
$conn = new PDO($base, $config["database"]["user"], $config["database"]["pass"]);
$query = $conn->query("SELECT setting, value FROM main");
if(!$query->rowCount()){
echo "An error occured while trying to load some important information. Please check your database credentials and data and try again.";
}
else{
$result = $query->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_GROUP);
var_dump($result);
}
例如,假设我的表中有以下数据:
setting | value
------------------
one | 1
------------------
two | 2
------------------
调用函数 var_dump() 将打印出:
array(2) {
["one"]=> array(1) {
[0]=> string(56) "1"
}
["two"]=> array(1) {
[0]=> string(24) "2"
}
}
array(2) {
["one"]=> array(1) {
[0]=> string(56) "1"
}
["two"]=> array(1) {
[0]=> string(24) "2"
}
}
array(2) {
["one"]=> array(1) {
[0]=> string(56) "1"
}
["two"]=> array(1) {
[0]=> string(24) "2"
}
}
array(2) {
["one"]=> array(1) {
[0]=> string(56) "1"
}
["two"]=> array(1) {
[0]=> string(24) "2"
}
}
有人知道为什么会这样吗?