2012-06-18 54 views
0

我正在用PHP編寫代碼來將數據從mySQL數據庫基本上映射到另一個數據庫。我使用的代碼如下:在蛋糕php中查詢函數

$results = $this->query("select PT_FS_DATA_ID from PATIENT_FLOWSHEET_DATA where 
    DT_LAST_UPDATED_TIME = (select top 1 DT_LAST_UPDATED_TIME from PATIENT_FLOWSHEET_DATA 
    order by DT_LAST_UPDATED TIME desc) group by PT_FS_DATA_ID;"); 

但是,我得到一個錯誤:

syntax error, unexpected T_VARIABLE, expecting T_FUNCTION 

我到處看,這似乎是正確的語法。有什麼我在這裏失蹤? 我試着把控制器也放在那裏$this->controllerName->query,但那也沒用。

全碼:

class CaExtraFlowsheetFields extends CaBase { 
public $name = 'CaExtraFlowsheetFields'; 

/* 
NOTE: This is to take all the fields in flowsheet and 
maps their id's. 
*/ 
//public $useTable = 'ANSWER_ENTRY'; 
public $useTable = 'PATIENT_FLOWSHEET_DATA'; 
public $primaryKey = 'PT_FS_DATA_ID'; 

protected function getPrimaryKeyValue(
    $hospital_id, 
    $patient_id, 
    $admission_id = null 
) { 

return $patient_id; 
} 

//*CHANGE BEGIN* 
$results = $this->query("select PT_FS_DATA_ID from PATIENT_FLOWSHEET_DATA where 
DT_LAST_UPDATED_TIME = (select top 1 DT_LAST_UPDATED_TIME from PATIENT_FLOWSHEET_DATA 
order by DT_LAST_UPDATED TIME desc) group by PT_FS_DATA_ID;"); 

protected $filedMethodMappings = array(

    'Method_GO' => array(
     CaBase::KEY_MAPPING_LOGIC_COMPLEXITY => CaBase::LEVEL2_COMPLEXITY, 
     CaBase::KEY_FIELD_LOGIC_NAME   => 'wsMethod_GO', 
); 

//########################################################################// 
//Note[]>Block[]    // 
//>Method that calls LookUpField for every field in flowsheet //          // 
//########################################################################// 
public function wsMethod_GO ($params) { 
    foreach($results as $value){ 

     $questionName = ''.$value; 
     $msg_prefix = $this->name . "::" . __FUNCTION__ . ": ". "arrivez-vouz" ; 
     $ret = $this->wsLookUpField($params,$questionName,$msg_prefix); 
     return $ret; 
    } 
    unset($value); 
} 
//########################################################################// 

public function wsLookUpField($params,$questionName,$msg_prefix){ 

$arrayValues=array(); 
    try{  
     $hospital_id = $params[Constants::KEY_HOSPITAL_ID]; 
     $patient_id = $params[Constants::KEY_PATIENT_ID]; 
     $admission_id = $params[Constants::KEY_ADMISSION_ID]; 

     $msg_prefix = $this->name . "::" . __FUNCTION__ . ": ". "attendez-vouz: l'hopital= ".$hospital_id. 
     " patient= ".$patient_id." admission= ".$admission_id; 

     //shows info about given question name 
     $msg_prefix = "*!*!*!*Show me ---> ".$questionName." : ".$answer_entry_id. 
     " = aic: " .$answer_id_check; 

     $ret = array(); 

     //now with needed fields, grab the A_NAME: 
      $params = array(
      'conditions' => array(
       $this->name . '.PID'    => $patient_id, 
       $this->name . '.PT_FS_DATA_ID'  => $questionName,   
      ), 
      'order' => array(
       $this->name . '.' . $this->primaryKey . ' DESC' 
      ), 
      'fields' => array(
       $this->name . '.FS_VALUE_TEXT', 
      ) 
     ); 

    $rs = $this->find('first', $params); 

    /* check to make sure $rs has received an answer from the query 
     and check to make sure this answer is a part of the most recent 
     database entries for this note */ 
    if (false != $rs) { 
      try {     
       $msg = $msg_prefix . "Data obtained successfully."."<br>".$result; 
      $result = $rs; 
      $ret = WsResponse::getResponse_Success($msg, $result); 
     } catch (Exception $e) { 
      $msg = $msg_prefix . "Exception occurred."; 
      $ret = WsResponse::getResponse_Error($msg); 
     } 
    /*answer was not part of most recent database entries, meaning no 
     answer was given for this particular question the last time this 
     particular note was filled out. Message is given accordingly.*/ 
    } else { 
     $msg = $msg_prefix . "/No answer given."; 
      $ret = WsResponse::getResponse_Error($msg); 
     } 


    } catch (Exception $e) { 
       $msg = $msg_prefix . "Exception occurred."; 
       $ret = WsResponse::getResponse_Error($msg); 
     }   
return $ret; 
} 
+0

您在模型上進行查詢時?另外,查看錯誤引用的行號。 – jeremyharris

+0

行號是$ results = $ this-> query(「從PATIENT_FLOWSHEET_DATA中選擇PT_FS_DATA_ID,其中,當我執行查詢時,我在模型中 – nathpilland

+0

您能顯示更多代碼嗎?這確實是有效的代碼,所以我覺得我們在其他地方錯過了一些東西 – jeremyharris

回答

2

這裏是你在做什麼:

class ABC { 

    $result = 'whatever'; 

} 

你不能聲明一個變量有!


代碼需要一個方法/函數裏面......

class ABC 
{ 
    public function wsMethod_GO ($params) 
    { 
     $result = 'whatever'; 
    } 
} 
+0

你能解釋一下嗎?我不確定你的意思。 – nathpilland

+0

哦!我甚至都沒有想過這件事。最近幾天。謝謝!!但是現在我得到了意想不到的T_PUBLIC。我需要聲明一些私人的東西才能使之有效嗎? – nathpilland