0

我不断收到一个数组到字符串转换的通知,这似乎是我已经转义(或没有转义)MySQL 语句的方式。如果我不使用 PHP 变量并将数据作为文本放入它可以工作,但使用变量它会显示错误。帮助!:)

function lastBackupStatus($server,$node){
  $serverstatus = "";
  $i=1;
  $result = mysql_query("select
    max(case when status LIKE '%Failed%' then scheduled_start end) Last_Failed,
    max(case when status LIKE '%Missed%' then scheduled_start end) Last_Missed,
    max(case when status LIKE '%Completed%' then scheduled_start end) Last_Completed,
    node_name,
    schedule_name
    from `events_".$server."`
    where node_name='".$node."'
    group by node_name, schedule_name
    ORDER BY last_failed");
  $count=mysql_num_rows($result);
  if ($count!== 0){
    while ($info = mysql_fetch_assoc( $result )){
      if($i < $count){
        $serverstatus .="";//do nothing
      }else{
        if($info['Last_Failed']  > $info['Last_Completed']){
          if($info['Last_Failed'] > $info['Last_Missed']){
            $serverstatus .="Failed:". $info['Last_Failed'].
              $info['node_name'].$info['schedule_name']."</br>";
          }
        }
        if($info['Last_Missed'] > $info['Last_Completed']){
          if ($info['Last_Missed'] > $info['Last_Failed']){
            $serverstatus .=" Missed: ". $info['Last_Failed'].
              $info['node_name'].$info['schedule_name']."</br>";
          }
        }
      }
      $i++;
    }
  } else {
    $serverstatus .= "count is 0";
  }
  return $serverstatus;
}
4

1 回答 1

0

您忘记了AS关键字:

max(case when status LIKE '%Failed%' then scheduled_start end) Last_Failed, 
max(case when status LIKE '%Missed%' then scheduled_start end) Last_Missed,
max(case when status LIKE '%Completed%' then scheduled_start end) Last_Completed,

应该

max(case when status LIKE '%Failed%' then scheduled_start end) AS Last_Failed, 
max(case when status LIKE '%Missed%' then scheduled_start end) AS Last_Missed,
max(case when status LIKE '%Completed%' then scheduled_start end) AS Last_Completed,

因此$info['Last_Failed']没有关联索引等。

根据您的评论,它$node毕竟是一个数组,您需要替换它:

where node_name='".$node."'

有了这个:

where node_name='".$node['node_name']."'
于 2013-01-30T21:58:01.973 回答