PDO query returns result, but i cant fetch it

Hello im trying out PDO and im stucked in a weird situation.


returns me the desired results, but when i try to fetch em , while doesnt seem to work. I tried use $statement->fetchAll() with foreach but it doesnt work either.

I also tried fetch(PDO::FETCH_ASSOC) but again no luck. AM i doing something wrong ?

$pdoObject = new PDO("mysql:host=$dbhost;dbname=$dbname;", $dbuser, $dbpass);
$pdoObject -> exec("set names utf8");
$sql="SELECT * from prokiriksi_clean where name=:name";
$statement = $pdoObject->prepare($sql);
$statement->execute(array(':name' =>$clean));
var_dump($testyo); //returns array

if ($statement->fetch()){
  echo 'inside if'; //it is printed
  while ($record =  $statement->fetch()) {
  var_dump($record); //doesnt print
  echo 'inside while'; //doesnt print

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s