我一直在获取一个数组到字符串转换的通知,它似乎来自我已经转义(或没有转义)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;
}
答案 0 :(得分: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']."'