【发布时间】:2018-03-04 00:43:50
【问题描述】:
好的,来自here 上的另一个用户问题我有以下问题:
set @test = 0, @id=0, @count=0;
select m.id, max(count)
from (
select
@count := if(TookTest = 1 and PatientID = @id, @count+1, 0) as count,
@test := Tooktest,
@id := PatientID as id
from medical) as m
group by m.id
having max(count) >=2;
这在 phpmyadmin 中运行良好,但是当我在 PDO 语句中尝试相同时,它会失败并显示以下错误消息:
PDOException: SQLSTATE[HY000]: 一般错误
$sql="set @test = 0, @id=0, @count=0;
select m.id, max(count)
from (
select
@count := if(TookTest = 1 and PatientID = @id, @count+1, 0) as count,
@test := Tooktest,
@id := PatientID as id
from medical) as m
group by m.id
having max(count) >=2;";
try{
$stmt=$dbh->prepare($sql);
if ($stmt->execute()){
$rows=$stmt->fetchall();
}
}catch(PDOException $s){
echo $s;
}
我是否缺少一些东西,比如你不能在 PDO 语句中设置变量?
【问题讨论】:
-
mysqli / pdo 不允许您在一次执行中执行多个语句。即select * from;select count from;
标签: php mysql variables pdo phpmyadmin