title: Unable to connect to fetch the data using php class
body: <p>I'm using XAMPP on Windows XP and when I try to fetch the data from table i am getting below Warnings but not data.</p>
  <blockquote>
  <p>Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in D:\xampp\htdocs\Chil\class.StudentDet.php on line 10</p>
  <p>Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in D:\xampp\htdocs\Chil\class.StudentDet.php on line 10</p>
  </blockquote>
  <p>Please find the code below.</p>
  <p>Code:</p>
  <pre><code>class.DBConnection.php
  
     &lt;?php
  
        class DBConnection //create a class for make connection
        {
           var $host='localhost';
           var $username='root';    // specify the sever details for mysql
           Var $password='';
           var $databaseName='test';
           var $connectionString;
  
  function connectToDatabase() // create a function for connect database
  {
  $this -&gt; connectionString = mysql_connect($this-&gt;host,$this-&gt;username,$this-&gt;password);             
      if(!$connectionString)// testing the connection
      {
          die (&quot;Cannot connect to the database&quot;);
      }       
      mysql_select_db($this -&gt; databaseName,$this -&gt; connectionString);
      if(mysql_error()) // if error occured display the error message
      {
          echo &quot;Cannot find the database &quot;.$this-&gt;database;
      }
      return $this -&gt; connectionString;
  }
   function closeConnection() // close the connection
  {
      mysql_close($this-&gt;connectionString);
  
      echo &quot;Connection closed&quot;;
   }
   }
  ?&gt;
  </code></pre>
  <p>class.StudentDet.php</p>
  <pre><code> &lt;?php
      require_once('class.DBConnection.php');
      class StudentDet{   
  
      function getStudDet(){  
      $connection = new DBConnection();
      $connection-&gt;connectToDatabase();
      $ct=&quot;SELECT * FROM students where course='Testing'&quot;;        
      $result = mysql_query($ct); 
      return $result;  
   }
    }
   ?&gt;
  </code></pre>
  <p>In Php Page</p>
  <p>StudentInfo.php</p>
  <pre><code>     &lt;?php
  
        include ('class.StudentDet.php');
        $stud = new StudentDet;
        $fetch = $stud-&gt;getStudDet();
        print '$fetch';
      ?&gt;
  </code></pre>
  <p>Please help me out on this.</p>