0

Here I am calling some data from database but something seems to have gone wrong, though no error is displayed but data isn't selected I used echo to test nothing came out, data is their in database but this statement doesn't select it.

$que =$db->prepare("SELECT first_name, last_name, bio FROM userss WHERE username=:username");
$que->execute(array(':username'=>$username));
$row = $que->fetch(PDO::FETCH_ASSOC);
$db_first_name = $row['first_name'];
$db_last_name = $row['last_name'];
$db_bio = $row['bio'];
  • 1
    What is the output of `var_dump($row);` – Tamil Selvan C Oct 04 '15 at 13:09
  • 1
    Did you really name your table `userss`? Seems like a typo to me – Sjon Oct 04 '15 at 13:12
  • 1
    You see no errors because you are not checking for any errors. After the `prepare` and `execute` you should be checking status or if you have configured your connection to throw exception, running the code in a try/catch block. *it would be useful to see the connection script as well* – RiggsFolly Oct 04 '15 at 13:14

1 Answers1

0

To know for sure you are not getting any errors, you have to look for them

I assume you have not set the connection to throw exceptions so if you add some error checking like this you will know for sure there are no errors, or what they are if they happen.

$que =$db->prepare("SELECT first_name, last_name, bio 
                    FROM userss WHERE username=:username");
if ( ! $que ) {
    print_r($db->errorInfo());
    exit;
}

$que->execute(array(':username'=>$username));
if ( ! $que ) {
    print_r($que->errorInfo();
    exit;
}

$row = $que->fetch(PDO::FETCH_ASSOC);
$db_first_name = $row['first_name'];
$db_last_name = $row['last_name'];
$db_bio = $row['bio'];
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149