title: PHP PDO statements similar to mysql_fetch_row($query, MYSQL_ASSOC))
body: <p>I am trying to fetch query results so i can use the data from mysql as variables on my page </p>
  
  <p>here in the given code i have hardcoded the hotel value as 105 but i am trying to get the value from an other page as get .</p>
  
  <pre><code> $ratedID =$_GET['ratedhotel'];
  </code></pre>
  
  <p>Here the body of my page is embedded under while.but the page is always empty.and this is what i have at the moment.</p>
  
  <pre><code>$hotel=$database-&gt;query('SELECT * FROM rate WHERE HotelID=:hotel ');
  $database-&gt;bind(':hotel', '105');
  $hotel-&gt;setFetchMode(PDO::FETCH_ASSOC);
  while($r = $hotel-&gt;fetch())
  </code></pre>
  
  <p>Below Is what i had before.</p>
  
  <pre><code> //$query = $db-&gt;query("SELECT * from rate WHERE        HotelId='$ratedhotelID'");
     //while($hotel = mysql_fetch_row($query, MYSQL_ASSOC))
  </code></pre>
  
  <p>I have some defined functions which I got as a library to use.</p>
  
  <pre><code>   &lt;?php
      class Database{
      private $host=DB_HOST;
      private $user=DB_USER;
      private $pass=DB_PASS;
      private $dbname=DB_NAME;
      private $stmt;
      private $dbh;
      private $error;
  
      public function __construct()
      {
      // Set DSN
      $dsn = 'mysql:host=' . $this-&gt;host . ';dbname=' . $this-&gt;dbname;
      // Set options
      $options = array(
      PDO::ATTR_PERSISTENT    =&gt; true,
      PDO::ATTR_ERRMODE       =&gt; PDO::ERRMODE_EXCEPTION
      );
      // Create a new PDO instanace
         $this-&gt;dbh = new PDO($dsn, $this-&gt;user, $this-&gt;pass, $options);
  
      }
  
  
  
      public function query($query){
          $this-&gt;stmt = $this-&gt;dbh-&gt;prepare($query);
      }
  
  
  
      public function bind($param, $value, $type = null){
          if (is_null($type)) {
              switch (true) {
                  case is_int($value):
                      $type = PDO::PARAM_INT;
                      break;
                  case is_bool($value):
                      $type = PDO::PARAM_BOOL;
                      break;
                  case is_null($value):
                      $type = PDO::PARAM_NULL;
                      break;
                  default:
                      $type = PDO::PARAM_STR;
              }
          }
          $this-&gt;stmt-&gt;bindValue($param, $value, $type);
      }
  
      public function execute(){
          return $this-&gt;stmt-&gt;execute();
      }
  
      public function resultset(){
          $this-&gt;execute();
          return $this-&gt;stmt-&gt;fetchAll(PDO::FETCH_ASSOC);
      }
  
  
      public function single(){
          $this-&gt;execute();
          return $this-&gt;stmt-&gt;fetch(PDO::FETCH_ASSOC);
      }
  
      public function rowCount(){
          return $this-&gt;stmt-&gt;rowCount();
      }
  
  
      }
  </code></pre>
  
  <p>I am not sure and am new to PDO .Any help will be much appreciated.</p>
  
  <p>Jai</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I made Changes to php and the code is like below:</p>
  
  <pre><code>$database= new Database();
  $database-&gt;query('SELECT * from rated where HotelID =:hotel');
  $database-&gt;bind(':hotel', $HotelID);
  //echo $database-&gt;resultset();
  $rows=array();
  $rows= $database-&gt;resultset(PDO::FETCH_ASSOC);
  //while($rows= $database-&gt;resultset());
  //while($hotel = $q-&gt;fetchAll(PDO::FETCH_ASSOC));
    { 
    echo "&lt;pre&gt;";
  print_r($rows);
  echo "&lt;/pre&gt;";
    echo "&lt;div&gt;'.$rows[LowRate].'&lt;div&gt;";
  
  
    };
    ?&gt;
  </code></pre>
  
  <p>So based on the above i can see the array on my page so the query works.
  But I want to use the variables in my html like.</p>
  
  <pre><code>&lt;p class="price-display-large page-price-text"&gt;'.$rows[LowRate].''.rows[PropertyCurrency].'&lt;/p&gt;
  </code></pre>
  
  <p>But this does not work.</p>