2010-09-14 82 views
1

我的網站在我的本地主機上正常工作。但是,當我上傳了最新的東西到服務器,我收到以下錯誤:在本地主機上工作,但在部署到服務器時出現錯誤

[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 

下面的代碼:

下面是我把服務器上。它會拋出上述錯誤。這不太漂亮,但它在本地工作。本地主機版本和服務器版本之間的唯一區別是第一次需求的路徑。我有正確的道路,因爲它對我所有其他的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

+1

對我來說很明顯'$ query'沒有被定義,所以我們知道你所有的'IF'條件都失敗了。我建議在腳本運行時添加一些'echo'語句來識別'$ schoolYear'和'$ schoolType',因爲它們顯然不是您期望的那樣... – Drew 2010-09-14 03:04:39

+0

嗨Andrew Heath,感謝您的留言。你很近。問題出在$ schoolPollSelections。 – Laxmidi 2010-09-17 00:09:10

回答

0

好吧,我想通了。我在發佈版本中使用了一個Alert來跟蹤一個設置$ schoolPollSelections的Flex變量。它顯示變量沒有被我的radioButton和列表控件設置。該變量是MyScoreData使用的一組參數。因此,MyScoreData無法獲取數據。

奇怪的是,當我在本地主機上跟蹤它時,變量顯示爲具有所有參數。但是,它在遠程服務器上時沒有設置。我不知道爲什麼。無論如何,我已經在兩臺主機上正確設置了變量,並且它可以正常工作。

謝謝Stoosh,Marc B和Andrew Heath的熱心幫助。

1

如果要包括或需要的文件或查詢變量來自另一個文件,確保文件和庫所有的路徑是在服務器上是正確的,他們可能是對的路徑不同的當地發展環境。

你能不能也請發佈代碼?

+0

嗨Stoosh,謝謝你試圖幫助我。我已經發布了這個課程。這是一種醜陋的意大利麪條,但它在當地有用。如果您有任何建議,請讓我知道。我會再次檢查路徑(再次)。 – Laxmidi 2010-09-14 02:23:09

0

最有可能的是怎麼發生的是,你檢查在if()聲明匹配那個球的選項NONE,所以$query從未定義,當代碼到達mysql_query()線,它試圖運行一個NULL查詢,基本上$result = mysql_query('');

我懷疑如果你改變實際的查詢電話線,以這樣的:

$result = mysql_query($query) or die("MySQL error: " . mysql_error()); 

你會看到腳本中止在與「空查詢」錯誤信息點。現在,函數調用很可能返回FALSE以指示發生錯誤,然後嘗試在mysql_fetch_assoc()中使用FALSE值,該值產生... not a valid MySQL result resource錯誤。

要解決此問題,請在所有if()語句之前放置默認查詢,以便如果沒有任何選項匹配,您仍然有某種有效查詢。或者,如果你不想運行在這一點上查詢,你可以環繞查詢/在if獲取模塊:

if (!empty($query)) { 
     $result = mysql_query(...) 
     // etc... 
     return($ret); 
} else { 
     return($some_default_value_to_signify_nothing_was_done); 
} 
相關問題