从DB中检索数据时出错

时间:2014-06-17 19:07:25

标签: php mysql database pdo

我从数据库请求此数据并且工作正常,

<?php
                                    $stmt = $con->query('SELECT * FROM blogData ORDER BY id DESC');
                               while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
                                $title    = htmlspecialchars($row['title']);
                                $content  = htmlspecialchars($row['content']);
                                $category = htmlspecialchars($row['category']);

                     ?>
                    <div class="features">
                        <div class="box"><img src="Developer/common-files/icons/time@2x.png" width="100" height="100" alt="Wuno Inc.">       
                             <h6><?php echo htmlspecialchars($category); ?> - <?php echo htmlspecialchars($title); ?></h6>
                             <p><?php echo htmlspecialchars($content); ?></p>
                        </div>
                    </div>
                      <?php
                      }
                      ?>

然后当我用这样的不同表做同样的事情时,

 $stmt = $con->query('SELECT * FROM taggePlaces ORDER BY created_time DESC');
                                       while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
                                            $id   = htmlspecialchars($row['id']);
                                            $created_time = htmlspecialchars($row['created_time']);
                                            $place_id = htmlspecialchars($row['place_id']);
                                            $city = htmlspecialchars($row['city']);
                                            $country = htmlspecialchars($row['country']);
                                            $latitude = htmlspecialchars($row['latitude']);
                                            $longitude = htmlspecialchars($row['longitude']);
                                            $state = htmlspecialchars($row['state']);
                                            $street = htmlspecialchars($row['street']);
                                            $zip = htmlspecialchars($row['zip']);
                                            $name = htmlspecialchars($row['name']);

我收到此错误,我无法弄清楚原因......

Fatal error: Call to a member function fetch() on a non-object in 

错误在while loop

的行上

我发现这个帖子显然解释了同样的问题,但我不明白为什么或解决方案。

Stack Overflow Q&A

NoteORDER BY created_time DESC是时间戳

0 个答案:

没有答案
相关问题