我在Windows XP上使用XAMPP,当我尝试从表中获取数据时,我的数据低于警告但不是数据。
警告:mysql_query()[function.mysql-query]:在D:\ xampp \ htdocs \ Chil \ class.StudentDet.php上用户'ODBC'@'localhost'(使用密码:NO)拒绝访问10
警告: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 Page
中StudentInfo.php
<?php
include ('class.StudentDet.php');
$stud = new StudentDet;
$fetch = $stud->getStudDet();
print '$fetch';
?>
请帮我解决这个问题。
答案 0 :(得分: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;
}