0

newbie PDO question...

I think (hard to tell - buried in a wrapper class) I am doing a select query using:

PDO::FETCH_ASSOC

wrapper:

return $pdostmt->fetchAll(PDO::FETCH_ASSOC);

I am getting back just 1 record - like to display the results of just current customer....

My query is:

$results = $db->select("mytable", "id = 201"); //just 1 exact record)

then I can loop like:

foreach ($results as $result) {
.... 
?>

<tr>
<td><?php echo $result["First"]; ?></td>
<td><?php echo $result["Last"]; ?></td>
<td><?php echo $result["id"]; ?></td>

</tr>

This all works fine, but since I only have 1 exact CUSTOMER record - I don't need to LOOP anything.

My question is:: How do I display the columns without a loop?

The following failed:

echo $results["First"];
echo $results["First"][0];
echo $results["First"][1];

So what can I use to make it work?

4

2 回答 2

1

Use fetch instead of fetchAll

$row = $pdostmt->fetch(PDO::FETCH_ASSOC);
于 2013-06-17T03:35:48.877 回答
1

You have to use the fetch function of PDO library.

于 2013-06-17T03:42:19.673 回答