ソースコード:
<?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
)