真正的基础:
$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像这样返回?
答案 0 :(得分:2)
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
它不在fetchAll
文档中,但它位于fetch
文档中。