dongying3830 2012-06-21 13:16
浏览 115
已采纳

如何“分解”我的PDO查询返回的数组?

So just as I began to get a good grasp on MySQL, I found out I should be learning about PDO. This is the (unfinished) code I have so far. I'd like to get it working before worrying about adding more password security. When I run the script, the printed message is "Array". How can I break this down and retrieve the data in the array?

try {
$db = new PDO($dbhost, $dbuser, $dbpassword);
$statement = $db->prepare("select * from users where email = :name");
$statement->execute(array(':name' => $username));
$result = $statement->fetch();
echo $result;}

catch(PDOException $e) {echo $e->getMessage();}

Sorry if this is a silly question; I've been searching for a while, but can not find any good examples what match what I'm doing, and I learn better from examples than long, wordy descriptions (such as the PHP manual).

  • 写回答

1条回答 默认 最新

  • dongmi0760 2012-06-21 13:23
    关注

    You might want to review your PHP base first, these pages seems most appropriate:

    http://php.net/manual/en/language.types.array.php

    Then, you can review again the code for Fetch and FetchAll at:

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

    Note that arrays are the defacto standard when receiving data from any provider, should it be pdo, mysql, mysqli, pgsql, this is why i recommend you review the ARRAY type first, get a good grasp of it, then read PDO stuff again...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?