Getting first element from PDOStatement

I am performing an sql query using PDO. In the resulting PDOStatement, there is only one column. If i use PDOStatement->fetch(); would it serve my purpose?

Answers


Yes, although fetchColumn() would probably be more convenient as the return value will be scalar.

echo $stmt->fetchColumn();

otherwise you could do the following, or many variations of

$row = $stmt->fetch(PDO::FETCH_NUM);
echo $row[0];

Need Your Help

Remove Some HTML tags with RegExp and Java

java html regex

I want to remove HTML tags from a String.

How to dynamically update an image gallery upon the photos taken from the native camera in android?

android android-camera image-gallery

Here is my image gallery code. So far, for testing purpose I directly used some manually stored images,