PHP PDO postgresql -- 我只想要哈希名称,而不是数字?
这里是真正的基本:
$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 像这样返回?
Real basic here:
$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();
But my return is of course:
Array
(
[0] => Array
(
[Something] => foo
[0] => foo
[somethingElse] => herp
[1] => herp
[AnotherSomethingElse] => derp
[2] => derp
)
)
But I just want
Array
(
[0] => Array
(
[Something] => foo
[somethingElse] => herp
[AnotherSomethingElse] => derp
)
)
Without post-processing to remove array elements, how do I get PDO to return like this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它不在
fetchAll
文档中,但在fetch
文档中。http://www.php.net/manual/en/pdostatement.fetch.php
It's not in the
fetchAll
documentation, but it is in thefetch
documentation.http://www.php.net/manual/en/pdostatement.fetch.php