// Check for existence - don't add a duplicate
$sqlQuery = $pdo->prepare('SELECT campaign_id FROM campaigns WHERE (customer_id=:customerId) AND (title=:campaignTitle) AND (description=:campaignDescription) AND (start_time=:startTimeStamp) AND (end_time=:endTimeStamp)');
$sqlQuery->bindParam(':customerId', $customerId); // , PDO::PARAM_INT
$sqlQuery->bindParam(':campaignTitle', $campaignTitle);
$sqlQuery->bindParam(':campaignDescription', $campaignDescription);
$sqlQuery->bindParam(':startTimeStamp', $campaignTitle);
$sqlQuery->bindParam(':endTimeStamp', $endTimeStamp);
$sqlResult = DatabaseCommand($sqlQuery);
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':customerId) AND (title=:campaignTitle) AND (description=:campaignDescription) A' at line 1' in E:\coding\Web Development\Xampp\htdocs\api\addCampaign.php:42 Stack trace: #0 E:\coding\Web Development\Xampp\htdocs\api\addCampaign.php(42): PDO->query('SELECT campaign...') #1 {main} thrown in E:\coding\Web Development\Xampp\htdocs\api\addCampaign.php on line 42
,但我不明白爲什麼
[更新]對於那些誰希望看到的DatabaseCommand()
這個代碼是相當多了。
function DatabaseCommand($sqlCommand)
{
$result = $sqlCommand->execute();
return $result;
}
有一些額外的代碼,但只是記錄命令用於調試鼠海豚,檢查錯誤,記錄這些,捕獲異常&電子郵件我。
語法看起來很好,所以很可能是訪問衝突。確保你對該數據庫/表具有所需的「讀取」權限。 –
Parenethis不需要。你可以發佈DatabaseCommand()方法嗎?該查詢如下所示:「SELECT campaign_id FROM campaigns WHERE customer_id =:customerId AND title =:campaignTitle AND description =:campaignDescription AND start_time =:startTimeStamp AND end_time =:endTimeStamp」。用第一個括號查詢是在哪裏(未設置)=(條件=值) –
什麼是'DatabaseCommand()'?它有什麼作用?該命令不是標準PDO afaik的一部分。 –