尝试获取一些数据库会导致一个非常简单的应用程序。
代码
$pdo = new PDO("mysql:host=localhost;dbname=soundinsider", "root", "");
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "SELECT * FROM users";
$query = $pdo->query($sql);
echo '<pre>';
print_r($query->fetchAll());
这就是输出
Array
(
[0] => Array
(
[user_id] => 1
[0] => 1
[username] => simon
[1] => simon
[email] => madeup
[2] => madeup
)
[1] => Array
(
[user_id] => 2
[0] => 2
[username] => bobwin
[1] => bobwin
[email] => fake@email.com
[2] => fake@email.com
)
)
所以似乎为每个结果创建了一个额外的键。当我在一两个月前进行编码时,情况并非如此。这里有什么问题还是现在是 PDO 行为?