我使用PHP执行SQL语句,但它返回“ PDO SQLSTATE [HY000]:常规错误”,但在“ phpMyAdmin”中有效,并且返回了我想要的结果。
这是我的代码,只是一个示例(可能包含一些错字)
try{
$query = $con->prepare("
set @pointA = (
SELECT tc.sort FROM tableC tc
INNER JOIN tableT tt ON tt.low = tc.id
WHERE tt.id = :this
);
set @pointB = (
SELECT tc.sort FROM tableC tc
INNER JOIN tableT tt ON tt.high = tc.id
WHERE tt.id = :this
);
set @main = (
SELECT tl.id FROM tableT tt
INNER JOIN tableC tcl ON tcl.id = tt.low
INNER JOIN tableC tch ON tch.id = tt.high
INNER JOIN tableL tl ON tch.pro= tl.id AND tcl.pro = tl.id
WHERE tt.id = :this
);
set @min = (
SELECT MIN(stage) FROM tableS
WHERE ((stage >= @pointA AND stage <= @pointB) AND status = 1)
);
set @max = (
SELECT MAX(stage) FROM tableS
WHERE ((stage >= @pointA AND stage <= @pointB) AND status = 1)
);
set @pointD = (
SELECT td.time FROM tableT tt
INNER JOIN tableD td ON td.pro = tt.id
WHERE tt.low = @pointA AND td.main = 1
);
SELECT @pointD AS DropPoint,@main AS MainProd, @min AS min, @max AS max,@pointA AS StartPoint,@pointB AS EndPoint,ts.type,ps.type AS typename,tf.price FROM tableS ts
INNER JOIN point_type pt ON pt.id = ts.type
INNER JOIN point_cost pc ON pc.pro = :this AND pc.type = ts.type
AND pc.layer = :layer
WHERE ts.no = :no and ts.main = @main
")
$query->bindParam(':no',$no);
$query->bindValue(':this',encode($target));
$query->bindParam(':layer',$random);
$query->execute();
while($x=$query->fetch(PDO::FETCH_ASSOC)){
//.......
}
}
catch(PDOException $x){
echo $x->getMessage();
}
我尝试在return false;
之后添加$query->execute();
,但没有返回任何错误,是fetch(PDO::FETCH_ASSOC)
造成的问题吗?