适用于Localhost,但在部署到服务器时出错

时间:2010-09-14 00:58:57

标签: php

我的网站在我的localhost上工作正常。但是,当我将最新的东西上传到服务器时,我收到以下错误:

[13-Sep-2010 20:40:22] PHP Notice:  Undefined variable: query in /home/mysite/public_html/zendamf_remote/MyScoreData.php on line 143
[13-Sep-2010 20:40:22] PHP Warning:  mysql_fetch_object(): supplied argument is not a valid MySQL result resource in /home/mysite/public_html/zendamf_remote/MyScoreData.php on line 146
[13-Sep-2010 20:40:22] PHP Warning:  mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/mysite/public_html/zendamf_remote/MyScoreData.php on line 156
[13-Sep-2010 20:40:29] PHP Notice:  Undefined variable: query in /home/mysite/public_html/zendamf_remote/MyScoreData.php on line 143
[13-Sep-2010 20:40:29] PHP Warning:  mysql_fetch_object(): supplied argument is not a valid MySQL result resource in /home/mysite/public_html/zendamf_remote/MyScoreData.php on line 146
[13-Sep-2010 20:40:29] PHP Warning:  mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/mysite/public_html/zendamf_remote/MyScoreData.php on line 156

以下代码:

以下是我放在服务器上的内容。它抛出上述错误。它不是太漂亮,但它在本地工作。 localhost版本和服务器版本之间的唯一区别是第一次需要的路径。我有正确的路径,因为它对我所有的其他php类都是一样的。

<?php
require_once('/home/mysite/connection/connection_mysite.php');
require_once('VOscore1.php');


class MyScoreData {

public function getScoreData($schoolPollSelections) {

        $schoolYear = $schoolPollSelections[0];
        $schoolType = $schoolPollSelections[1];
        $schoolGradeLevel= $schoolPollSelections[2];
        $schoolSubject = $schoolPollSelections[3];
        $myTable = 'mc_school_report_card_sy_'.$schoolYear;
        $myTable2 = 'mc_school_scores_sy_'.$schoolYear;


        if($schoolYear == '2009_2010') {

            if($schoolType == 'both'){
                if($schoolSubject == 'M'){$query = "SELECT DISTINCT school_name_sy09_10 AS school, ROUND(math_below_basic) AS percent_below_basic, ROUND(math_basic) AS percent_basic, ROUND(math_proficient) AS percent_proficient, ROUND(math_advanced) AS percent_advanced, ROUND(math_proficient + math_advanced) AS percent_proficient_and_advanced  FROM mc_school_scores_latlong WHERE category='$schoolGradeLevel' AND lea!='n' AND year='2010' AND status_sy09_10!='closed' AND status_sy09_10!='unknown' AND math_below_basic IS NOT NULL  AND grade_school_type_sy09_10!='Special Education School' ORDER BY percent_proficient_and_advanced DESC";}

        if($schoolSubject == 'R'){$query = "SELECT DISTINCT school_name_sy09_10 AS school, ROUND(reading_below_basic) AS percent_below_basic, ROUND(reading_basic) AS percent_basic, ROUND(reading_proficient) AS percent_proficient, ROUND(reading_advanced) AS percent_advanced, ROUND(reading_proficient + reading_advanced) AS percent_proficient_and_advanced  FROM mc_school_scores_latlong WHERE category='$schoolGradeLevel' AND lea!='n' AND year='2010' AND status_sy09_10!='closed' AND status_sy09_10!='unknown' AND reading_below_basic IS NOT NULL AND grade_school_type_sy09_10!='Special Education School' ORDER BY percent_proficient_and_advanced DESC";} 
            }

            else{

            if($schoolSubject == 'M'){$query = "SELECT DISTINCT school_name_sy09_10 AS school, ROUND(math_below_basic) AS percent_below_basic, ROUND(math_basic) AS percent_basic, ROUND(math_proficient) AS percent_proficient, ROUND(math_advanced) AS percent_advanced, ROUND(math_proficient + math_advanced) AS percent_proficient_and_advanced  FROM mc_school_scores_latlong WHERE category='$schoolGradeLevel' AND lea='$schoolType' AND lea!='n' AND year='2010' AND status_sy09_10!='closed' AND status_sy09_10!='unknown' AND math_below_basic IS NOT NULL  AND grade_school_type_sy09_10!='Special Education School' ORDER BY percent_proficient_and_advanced DESC";}

        if($schoolSubject == 'R'){$query = "SELECT DISTINCT school_name_sy09_10 AS school, ROUND(reading_below_basic) AS percent_below_basic, ROUND(reading_basic) AS percent_basic, ROUND(reading_proficient) AS percent_proficient, ROUND(reading_advanced) AS percent_advanced, ROUND(reading_proficient + reading_advanced) AS percent_proficient_and_advanced  FROM mc_school_scores_latlong WHERE category='$schoolGradeLevel' AND lea='$schoolType' AND lea!='n' AND year='2010' AND status_sy09_10!='closed' AND status_sy09_10!='unknown'  AND reading_below_basic IS NOT NULL AND grade_school_type_sy09_10!='Special Education School' ORDER BY percent_proficient_and_advanced DESC";}  
            }
        }



        if($schoolYear == '2008_2009') {

            if($schoolType == 'both'){
                if($schoolSubject == 'M'){$query = "SELECT DISTINCT school, ROUND(math_below_basic) AS percent_below_basic, ROUND(math_basic) AS percent_basic, ROUND(math_proficient) AS percent_proficient, ROUND(math_advanced) AS percent_advanced, ROUND(math_proficient + math_advanced) AS percent_proficient_and_advanced  FROM $myTable2 WHERE category='$schoolGradeLevel' AND lea!='n' ORDER BY percent_proficient_and_advanced DESC";}

        if($schoolSubject == 'R'){$query = "SELECT DISTINCT school, ROUND(reading_below_basic) AS percent_below_basic, ROUND(reading_basic) AS percent_basic, ROUND(reading_proficient) AS percent_proficient, ROUND(reading_advanced) AS percent_advanced, ROUND(reading_proficient + reading_advanced) AS percent_proficient_and_advanced  FROM $myTable2 WHERE category='$schoolGradeLevel' AND lea!='n' ORDER BY percent_proficient_and_advanced DESC";}    
            }

            else{

            if($schoolSubject == 'M'){$query = "SELECT DISTINCT school, ROUND(math_below_basic) AS percent_below_basic, ROUND(math_basic) AS percent_basic, ROUND(math_proficient) AS percent_proficient, ROUND(math_advanced) AS percent_advanced, ROUND(math_proficient + math_advanced) AS percent_proficient_and_advanced  FROM $myTable2 WHERE category='$schoolGradeLevel' AND lea='$schoolType' AND lea!='n' ORDER BY percent_proficient_and_advanced DESC";}

        if($schoolSubject == 'R'){$query = "SELECT DISTINCT school, ROUND(reading_below_basic) AS percent_below_basic, ROUND(reading_basic) AS percent_basic, ROUND(reading_proficient) AS percent_proficient, ROUND(reading_advanced) AS percent_advanced, ROUND(reading_proficient + reading_advanced) AS percent_proficient_and_advanced  FROM $myTable2 WHERE category='$schoolGradeLevel' AND lea='$schoolType' AND lea!='n' ORDER BY percent_proficient_and_advanced DESC";}  
            }
        }


        if(($schoolYear != '2008_2009') && ($schoolYear != '2009_2010') ) {

        if(($schoolType == 'D') || ($schoolType == 'P')) {$query = "SELECT DISTINCT school, ROUND(percent_below_basic) AS percent_below_basic, ROUND(percent_basic) AS percent_basic, ROUND(percent_proficient) AS percent_proficient, ROUND(percent_advanced) AS percent_advanced, ROUND(percent_proficient + percent_advanced) AS percent_proficient_and_advanced  FROM  $myTable WHERE  subgroup='Total' AND subject='$schoolSubject' AND category='$schoolGradeLevel' AND school_code NOT LIKE 'L%' AND school_code!='STATE' AND school!='BOE CHARTER' AND school!='TUITION GRANTS' AND lea='$schoolType' AND school!='LEA' AND school!='DCPS SCHOOLS' AND school!='PUBLIC CHARTER' ORDER BY percent_proficient_and_advanced DESC";}

        //if both is chosen as schooltype then it runs query below
        else {$query = "SELECT DISTINCT school,  ROUND(percent_below_basic) AS percent_below_basic, ROUND(percent_basic) AS percent_basic, ROUND(percent_proficient) AS percent_proficient, ROUND(percent_advanced) AS percent_advanced, ROUND(percent_proficient + percent_advanced) AS percent_proficient_and_advanced FROM  $myTable WHERE  subgroup='Total' AND subject='$schoolSubject'  AND category='$schoolGradeLevel' AND school_code NOT LIKE 'L%' AND school_code!='STATE' AND school!='BOE CHARTER' AND school!='TUITION GRANTS' AND school!='LEA' AND school!='DCPS SCHOOLS' AND school!='PUBLIC CHARTER' ORDER BY percent_proficient_and_advanced DESC";}

        }



         $mysql = mysql_connect(DATABASE_SERVER12, DATABASE_USERNAME12, DATABASE_PASSWORD12);
         mysql_select_db(DATABASE_NAME12);



            $result = mysql_query($query);

            $ret = array();
                 while ($row = mysql_fetch_object($result)) {
                    $tmp = new VOscore1();
                    $tmp->school = $row->school;
                    $tmp->percent_below_basic = $row->percent_below_basic;
                    $tmp->percent_basic = $row->percent_basic;
                    $tmp->percent_proficient = $row->percent_proficient;
                    $tmp->percent_advanced = $row->percent_advanced;
                    $tmp->percent_proficient_and_advanced = $row->percent_proficient_and_advanced;
                    $ret[] = $tmp; 
                        }
                 mysql_free_result($result);

                 return $ret;


    }       



}
?>

为什么它不在服务器上工作,但在本地工作的任何想法?我该怎么办?

感谢。

-Laxmidi

3 个答案:

答案 0 :(得分:1)

如果您包含或要求文件或查询变量来自另一个文件,请确保您在服务器上的所有文件和库路径都正确,它们可能与本地开发环境中的路径不同。

您能否发布代码?

答案 1 :(得分:0)

最有可能的是,您在if()语句中检查的选项中没有任何选项匹配,因此永远不会定义$query,并且当代码到达{{1}时它试图运行一个NULL查询,基本上是mysql_query()

我怀疑如果您将实际的查询调用行更改为:

$result = mysql_query('');

您会看到脚本在此时中止并显示“null query”错误消息。就目前而言,函数调用最有可能返回$result = mysql_query($query) or die("MySQL error: " . mysql_error()); 以指示发生错误,然后您尝试在FALSE中使用FALSE值,从而生成{{1}错误。

要修复,请在所有mysql_fetch_assoc()语句之前放置一个默认查询,这样如果所有选项都不匹配,您仍然会有某种有效查询。或者,如果您不想在此时运行查询,则可以在if:

中包围查询/获取块。
... not a valid MySQL result resource

答案 2 :(得分:0)

好的,我明白了。我在发布版本中使用了一个Alert来跟踪设置$ schoolPollSelections的Flex变量。它显示我的radioButton和list控件没有设置变量。此变量是MyScoreData使用的参数数组。因此,MyScoreData无法获取数据。

奇怪的是,当我在localhost上跟踪变量时,变量显示为具有所有参数。但是,当它在远程服务器上时,它没有设置。我不知道为什么。无论如何,我在两台主机上都正确设置了变量并且它可以工作。

感谢Stoosh,Marc B和Andrew Heath的帮助。