0

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
  • 1
    You'll want to retrieve it using a foreach for example. Lot's of tutorials out there. Take a look here for example Commented Jun 21, 2012 at 13:18

1 Answer 1

2

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...

Sign up to request clarification or add additional context in comments.

2 Comments

Also, i delocalized the mirror and used php.net by default, thx for mentionning Bono
I checked that out and managed to get it to work, thank you very much!