PHP PDO postgresql - 我只想要哈希名称,而不是计算?

时间:2011-05-03 15:47:44

标签: php postgresql pdo

真正的基础:

$db = new PDO("pgsql:dbname=gangsterbase;host=localhost", "sexyadmin", "ohhhhhyeahhhhh" );
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$stmt = $db->prepare("SELECT * FROM datFineLookinTable WHERE name LIKE :name ;");
$stmt->bindParam(':name', $name, PDO::PARAM_STR);

$stmt->execute();
$result = $stmt->fetchAll();

但我的回归当然是:

Array
(
    [0] => Array
        (
            [Something] => foo
            [0] => foo
            [somethingElse] => herp
            [1] => herp
            [AnotherSomethingElse] => derp
            [2] => derp
        )
)

但我只想要

Array
(
    [0] => Array
        (
            [Something] => foo
            [somethingElse] => herp
            [AnotherSomethingElse] => derp
        )
)

如果没有后处理来删除数组元素,我该如何让PDO像这样返回?

1 个答案:

答案 0 :(得分:2)

$result = $stmt->fetchAll(PDO::FETCH_ASSOC);

它不在fetchAll文档中,但它位于fetch文档中。

http://www.php.net/manual/en/pdostatement.fetch.php