0

I'm using PDO for the connection to my database. This is the code I'm using:

<?php
session_start();
if (ValidarCreacionUsuario($_POST)) {
    if (ValidarNoEmpty($_POST)) {
        $connection = new PDO('mysql:host=localhost;dbname=dbname', "dbuser", "dbpass");
        $sql = 'SELECT * FROM users WHERE username = :username AND password = :password';

        $statement = $connection->prepare($sql);

        $statement->bindParam(':username', $_POST['username'], PDO::PARAM_STR, 12);
        $statement->bindParam(':password', $_POST['password'], PDO::PARAM_STR, 30);
        $result = $statement->execute();

And then, I want to catch the value of the 'sex' column and the value of the 'id' column in my database, so, I think I have to use the fetchAll() or something like this, but I don't know how to use it or if I have to use it.
So, what do I have to use?

Thanks.

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
peregraum
  • 529
  • 1
  • 8
  • 19
  • 1
    You would be well advised to read the [PDO Manual](http://us3.php.net/pdo) – Patrick Q Mar 11 '14 at 17:01
  • You might also want to read [this](http://stackoverflow.com/questions/1197417/why-are-plain-text-passwords-bad-and-how-do-i-convince-my-boss-that-his-treasur) to save you from future ridicule. – Patrick Q Mar 11 '14 at 17:07
  • @PatrickQ Oh, thanks for the manual! I'll have a look at it! :D – peregraum Mar 11 '14 at 17:17

1 Answers1

0

something like this will show you what is available to you to use in an associative array (key and value)

$sql = "SELECT * FROM users... etc";
$stmt = $dbh->query($sql);


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

/*** loop over the object directly ***/
foreach($result as $key=>$val)
{
echo $key.' - '.$val.'<br />';
}
JamesMarc
  • 169
  • 1
  • 2
  • 12
  • Mmmm thanks, but what I want is to store the values into an array (sorry I forgot to mention this in the main post) – peregraum Mar 11 '14 at 17:14