-1

我在 Windows XP 上使用 XAMPP,当我尝试从表中获取数据时,我得到低于警告但不是数据。

警告:mysql_query() [function.mysql-query]:第 10 行 D:\xampp\htdocs\Chil\class.StudentDet.php 中的用户 'ODBC'@'localhost' 的访问被拒绝(使用密码:NO)

警告:mysql_query() [function.mysql-query]:无法在第 10 行的 D:\xampp\htdocs\Chil\class.StudentDet.php 中建立到服务器的链接

请在下面找到代码。

代码:

class.DBConnection.php

   <?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 -> connectionString = mysql_connect($this->host,$this->username,$this->password);             
    if(!$connectionString)// testing the connection
    {
        die ("Cannot connect to the database");
    }       
    mysql_select_db($this -> databaseName,$this -> connectionString);
    if(mysql_error()) // if error occured display the error message
    {
        echo "Cannot find the database ".$this->database;
    }
    return $this -> connectionString;
}
 function closeConnection() // close the connection
{
    mysql_close($this->connectionString);

    echo "Connection closed";
 }
 }
?>

class.StudentDet.php

 <?php
    require_once('class.DBConnection.php');
    class StudentDet{   

    function getStudDet(){  
    $connection = new DBConnection();
    $connection->connectToDatabase();
    $ct="SELECT * FROM students where course='Testing'";        
    $result = mysql_query($ct); 
    return $result;  
 }
  }
 ?>

在 PHP 页面中

学生信息.php

     <?php

      include ('class.StudentDet.php');
      $stud = new StudentDet;
      $fetch = $stud->getStudDet();
      print '$fetch';
    ?>

请帮我解决这个问题。

4

1 回答 1

0

在哪里调用这个函数?

function connectToDatabase() // create a function for connect database
{
$this -> connectionString = mysql_connect($this->host,$this->username,$this->password);             
    if(!$connectionString)// testing the connection
    {
        die ("Cannot connect to the database");
    }       
    mysql_select_db($this -> databaseName,$this -> connectionString);
    if(mysql_error()) // if error occured display the error message
    {
        echo "Cannot find the database ".$this->database;
    }
    return $this -> connectionString;
}
于 2013-04-08T02:44:17.423 回答