-1

ソースコード:

<?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
              )
4

3 に答える 3

0

フェッチ スタイルを手動で指定する必要があります。

$stmt->fetchAll(PDO::FETCH_ASSOC);
于 2013-05-10T09:16:55.980 に答える