-3

我遇到了问题,我将项目从 dev 下载到我的本地,虽然它在 dev 上运行良好,但在本地,它告诉我以下错误 Fatal error: Class 'DB' not found in F:\xampp\htdocs\第 9 行的 timesheet\index.php 我的 index.php 是

<?php
    session_start();
    error_reporting(1);
    include_once('classes/db.php'); 
    include_once('classes/functions.php');  

//==========================================
    $dbFun=new DB();
    $dbFun->ConnectToDb();
    $incFun= new Functions();
//==========================================
    if(isset($_GET['file'])){
         $file = $_GET['file'];
    }
    else if(isset($_POST['file'])){
         $file = $_POST['file'];
    }
    else{
           $file = "login.php";
    }  
?>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<title>::Administration::</title>
<? if(($file != "login.php") && ($_SESSION['sid'] != "")){?>
<link href="style.css" rel="stylesheet" type="text/css" />
<script src="js/CalendarPopup.js" type="text/javascript" language="JavaScript"></script>
<script type="text/javascript" src="js/sortable.js"></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.js"></script>
</head>
<body>

<table width="100%" height="90%" border="0"  align="center" cellpadding="0" cellspacing="0" bordercolor="#1F5F69">
<tr>
  <td height="36" colspan="3" valign="top">
  <table width="100%" height="150" border="0" cellpadding="0" cellspacing="0" style=" background:url(images/topbg.jpg); background-repeat: repeat-x;">

      <tr>

        <td width="30%" rowspan="2" align="left" valign="top"><img src="images/logo_quality_web_programmer.jpg" alt="Miami Truck Guide" width="351" height="151" /></td>

        <td width="70%" height="76" align="right" valign="top"><table width="500" border="0">
          <tr>
            <td align="right" style="color:#FFFFFF;">Welcome <? echo $_SESSION['sid'];?>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="?file=logout.php" style="color:#FFFFFF;">Logout</a>&nbsp;&nbsp;|&nbsp;&nbsp;Search</td>
            <td width="23">&nbsp;</td>
          </tr>

          <tr>
            <td align="right" valign="top"><span id="top-search"><form id="form1" name="form1" method="post" action=""><input name="search" type="text" id="search" />              
            <input type="image" src="images/search.png" name="Submit" value="Submit" /></form></span></td>
            <td>&nbsp;</td>
          </tr>
        </table></td>
      </tr>
    </table></td>
</tr>

<tr>

    <td width="213" rowspan="2" valign="top" style=" background:url(images/leftbg.jpg); background-repeat: repeat-x;">
    <? if($_SESSION['type'] == "Administrator"){
    include("admin_nav.php");
    } else{
    include("emp_nav.php");
    }?></td>
    <td width="11" rowspan="2" valign="top">&nbsp;</td>
    <td width="990" height="10" valign="top"></td>
</tr>
<tr>
  <td valign="top"><? include($file);?></td>
</tr>
</table>
<? } else { include("login.php");}?>

<script type="text/javascript">

$(document).ready(function(){

    //$('#pid').click(function(){
    $("select").change(function(){
    //alert("asma");
    var puid = $("#pid").val();
    document.getElementById(puid).style.display = 'block';
    });

    $("#button").click(function(){
    var frm = document.getElementById("leftform");
        frm.submit();
    });
});

</script>
</body></html>`

我的 db.php 是

<?
    //include("lang.inc.php");
//========================================
class Variables{ // database variables defined in the class

    var $dbServer;
    var $dbUser ;
    var $dbPass ;
    var $dbName ;

function Variables(){


    $this->dbServer = "localhost";
    $this->dbUser = "root";
    $this->dbPass = "";
    $this->dbName = "timesheet";
    }
}

//+----------------------------------------+
class DB  { // database class contains the function

    var $dbase;
    var $connection;

    function ConnectToDb()
    {
        // Connect to the database and return
        // true/false depending on whether or
        // not a connection could be made.

        $vari=new Variables();

        $this->connection = mysql_connect($vari->dbServer, $vari->dbUser, $vari->dbPass)
        or die("Could not connect : " . @mysql_error());                

        $this->dbase = mysql_select_db($vari->dbName, $this->connection);


        if(!$this->connection || !$this->dbase){            

            return false;
}
        else{                   

            return true;
            }
    }
//==============================    
    function selectMultiRecords($query)
     {   
        if((@$result = mysql_query ($query))==FALSE)
        {
            if (DEBUG=="True")
            {
                echo mysqlMessage($query);      
            }   
        }   
        else
        {   
            $count = 0;
            $data = array();
            while ( $row = mysql_fetch_array($result)) 
            {
                 $data[$count] = $row;
                 $count++;
                //echo "<br>";
            }
                return $data;
        }
    }       
//===============================
    function selectFrom($query)
    {
        if((@$result = mysql_query ($query))==FALSE) 
        {
            if (DEBUG=="True")
            {
                echo mysqlMessage($query);      
            }   
        }   
        else
        {   
            if ($check=mysql_fetch_array($result))
            {
                return $check;
            }
                return false;   
        }
    }
//==========================
function countRecords($query)
    {   
        $res = mysql_query($query);
        $results = mysql_num_rows($res);
        return $results;
    }       

//==============================    
function isExist($query) {  

       if((@$result = mysql_query ($query))==FALSE){
            if (DEBUG == "True"){
                echo mysqlMessage($query);      
            }   
        } else { 
            if ($check=mysql_fetch_array($result)){//mysql_fetch_array return flase if there are no records
                return $check;
            }
        return false;   
        }//else 
    }
        function insertInto($query)
    {   //echo $Querry_Sql;
       if((@$result = mysql_query ($query))==FALSE)
        {
            if (DEBUG=="True")
            {
                echo mysqlMessage($query);      
            }   
        }   
        else
        {   
            return true;    
        }
    }


    function deleteFrom($query)
    {
        if((@$result = mysql_query ($query))==FALSE)
        {
            if (DEBUG=="True")
            {
                echo mysqlMessage($query);      
            }   
        }   
        else
        {   
            return true;    
        }
    }

//================================
function update($query)
    {
        if((@$result = mysql_query ($query))==FALSE)
        {
            if (DEBUG=="True")
            {
              echo mysqlMessage($query);        
            }   
        }   
        else
        {   
            return true;
        }
    }   
    function mysqlMessage($query)
    {
        echo "<div align='left'><strong><font color='red'>Site Name &nbsp;&nbsp;e   r r o r:</font></strong><br>";
        echo "Error in your Query: $query<BR>";
        echo "<strong><font color='red'>m y s q l &nbsp;g e n e r a t e d &nbsp;e r r o r:</font></strong><BR>";
        echo mysql_errno() . " " . mysql_error() . "</div>";
    }   
    //Mail function
function mxmail($to,$subject,$msg, $fromname, $fromemail, $ishtml="true")
{
    $headers  = "MIME-Version: 1.0\r\n";
    if($ishtml=="true")
        $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
    else
        $headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";

    $headers .= "From: ".$fromname." <".$fromemail.">\r\n";

    @mail($to, $subject, $msg, $headers);
}       

}//========end of class 

?>
4

2 回答 2

4

在本地服务器上启用短标签。或者改变

<?

<?php

参考:http ://www.php.net/manual/en/ini.core.php#ini.short-open-tag

于 2012-08-15T00:35:38.957 回答
1

这看起来像一个路径问题。看起来 db.php 应该位于:

F:\xampp\htdocs\timesheet\classes\db.php

理想情况下,您应该指定要包含的文件的绝对路径,以便您的代码可以处理环境更改。有关详细信息,请参阅此问题的答案。

如果文件位于那里,请确保脚本对该文件具有读取权限。

于 2012-08-15T00:03:51.507 回答