簡體   English   中英

使用mysqli獲取數據

[英]using mysqli to fetch data

我一直在嘗試mysqli。

使用過程mysql,代碼可以很好地顯示結果。 但是,在切換到OOP mysqli之后,我嘗試將代碼轉換為mysqli,它說沒有引號。 代碼有什么問題嗎?

/* the database object */
        private $_db;

        public function __construct($db=NULL)
        {
            if(is_object($db))
            {
                $this->_db = $db;
            }
            else
            {

                $this->_db = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
            }
        }

        public function displayQuotes()
        {
            $sql = "SELECT cQuotes, vAuthor, cArabic, vReference 
                          FROM thquotes 
                          ORDER BY RAND()
                          LIMIT 1;";

                  try {

                      $query = $this->_db->prepare($sql);
                      $query->execute();
                      $query->store_result();

                      /* bind variables to prepared statement */
                      $query->bind_result($cQuotes, $vAuthor, $cArabic, $vReference);


                      if(!$query->num_rows==0)
                      {
                        while($row = $query->fetch())
                        {
                            //echo $this->formatQuotes($row);
                            $formatHTML = new formatHTML();
                            echo $formatHTML->formatQuotes($row);
                        }


                      }
                      else
                         {
                            echo "There are no Quotes!";
                         }
                       $query->free_result();
                      $query->close();
                    }
                  catch (Exception $ex){

                        echo "Something went wrong " . $ex;
                    }

        }

您沒有將變量綁定到結果集列

http://www.php.net/manual/zh/mysqli-stmt.bind-result.php

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM