Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to connect to fetch the data using php class
    text
    copied!<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 ("Cannot connect to the database"); } mysql_select_db($this -&gt; databaseName,$this -&gt; connectionString); if(mysql_error()) // if error occured display the error message { echo "Cannot find the database ".$this-&gt;database; } return $this -&gt; connectionString; } function closeConnection() // close the connection { mysql_close($this-&gt;connectionString); echo "Connection closed"; } } ?&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="SELECT * FROM students where course='Testing'"; $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>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload