源代码:
<?php
$dsn = 'mysql:dbname=oop;host=localhost;';
$user = 'admin';
$password = 'password';
try {
$pdo = new PDO($dsn, $user, $password);
} catch (PDOException $e)
{
echo 'Connection failed: ' . $e->getMessage();
}
$stmt = $pdo->prepare("select * from be_users");
$stmt->execute();
echo "<pre>";
print_r($stmt->fetchAll());
echo "</pre>";
?>
结果:
Array
(
[0] => Array
(
[username] => tom
[0] => tom
[email] => dsfde@gmail.com
[1] => dsfde@gmail.com
)
[1] => Array
(
[username] => tom3
[0] => tom3
[email] => sdfsdfs@gmail.com
[1] => sdfsdfs@gmail.com
)
...
问题:
为什么结果不是这样的:
Array
(
[0] => Array
(
[username] => tom
[email] => dsfde@gmail.com
)
[1] => Array
(
[username] => tom3
[email] => sdfsdfs@gmail.com
)