Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a PDO Fetch( ) to return as string

Tags:

arrays

php

pdo

How can I get a PDO to return the data as a string not an array? I am not sure this is possible so if not is there a way to convert the array to a string after it has been processed?

My code which is returning the string is:

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

I have tried different fetch types such as FETCH_CLASS FETCH_OBJ

like image 865
joshuahornby10 Avatar asked Jan 03 '13 22:01

joshuahornby10


1 Answers

You can do it like this:

echo $stmt->fetchColumn();    

Or:

$result = $stmt->fetch(PDO::FETCH_ASSOC);
echo $result[0];
like image 68
Joseph at SwiftOtter Avatar answered Sep 20 '22 06:09

Joseph at SwiftOtter