我的php腳本中有一個查詢由PDO處理。確切地說,它是1個聲明中的2個查詢。查詢本身在SQL客戶端中運行正常(我正在使用HeidiSQL)。然而,PHP給了我這個錯誤:「SQLSTATE [HY000]:一般錯誤」沒有別的。沒有錯誤號碼或消息。「SQLSTATE [HY000]:一般錯誤」 - 在一個語句中多個SQL查詢
有沒有辦法以某種方式調試查詢?我不認爲查詢本身存在錯誤,所以我不知道什麼是錯的。 mysql錯誤日誌中沒有顯示。我已經啓用了mysql通用日誌,但它只記錄查詢本身而不顯示錯誤。
我的堆棧:XAMPP 1.8,Apache的2.4.3,5.4.7 PHP,MySQL的5.5.27
這是我的查詢(這是相當長):
/*First query - generating temp table with overdue jobs*/
CREATE TEMPORARY TABLE temp AS (
SELECT j.NetworkID,
@clientID := j.ClientID,
j.BranchID,
j.ServiceProviderID,
(
(DATEDIFF(CURDATE(), j.DateBooked))
-
IF(
(@unit := (
SELECT uctype.UnitTurnaroundTime
FROM job
LEFT JOIN product ON job.ProductID = product.ProductID
LEFT JOIN unit_type AS utype ON product.UnitTypeID = utype.UnitTypeID
LEFT JOIN unit_client_type AS uctype
ON utype.UnitTypeID = uctype.UnitTypeID
AND uctype.ClientID = @clientID
WHERE job.JobID = j.JobID
)
) IS NOT NULL, /*statement*/
@unit, /*TRUE - Client Unit Type has turnaround time assigned in the db*/
IF( /*FALSE - Now checking if Client Default Turnaround Time is set*/
(@clnt := (
SELECT DefaultTurnaroundTime AS dtt
FROM client
WHERE client.ClientID = @clientID
)
) IS NOT NULL, /*statement*/
@clnt, /*TRUE - Client Default Turaround time is set*/
( /*FALSE - falling back to general default*/
SELECT gen.Default
FROM general_default AS gen
WHERE gen.GeneralDefaultID = 1
)
)
)
) AS overdue
FROM job AS j
HAVING overdue > 0
);
/*Second query - filtering out overdue jobs with specific time range*/
SELECT COUNT(*) AS number
FROM temp
WHERE overdue >= :from AND overdue <= :to AND overdue != 0
UPDATE:的問題似乎是由PDO拒絕在一個語句中運行多個查詢造成的。我在執行查詢之前已經插入這樣的:
$conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0);
所以現在「常規錯誤」走了,但我越來越
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax
只是第一次查詢後,意味着PDO只運行一個查詢並拒絕繼續...
這可能有助於http://stackoverflow.com/questions/6346674/pdo-support-for-multiple-queries-pdo-mysql-pdo-mysqlnd –
http://stackoverflow.com/questions/10199571/why- sqlstatehy000-general-error你是否解決了這個問題 – Drew
還沒有解決。閱讀這兩個帖子,雖然... – Caballero