我目前正在爲一個客戶端項目工作,但因爲我是pdo新手,我不知道如何處理它繼續吐出的錯誤。我正在使用的代碼也不是我的,所以這給混合添加了一些混淆。它不斷告訴我:PDO mysql錯誤
Query failed: 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 '' at line 1
我有誤差縮小到這些行:
$regid = $dbh->lastInsertId('');
$dupsid = true;
while ($dupsid){
srand((double)microtime()*1000000);
$maxrand = 100000000;
$rand_sid = rand();
$check_sid = "select reguniqid from v_events_registrants where reguniqid = :RAND_SID";
$stmt = $dbh->prepare($check_sid);
$stmt->bindValue(':RAND_SID', $rand_sid);
$stmt->execute();
$num_result = $stmt->rowCount();
if ($num_result == 0) $dupsid = false;
}
$uniqid_upd = "update v_events_registrants set reguniqid = :RAND_SID where registrant_id = :REGID";
$stmt = $dbh->prepare($uniqid_upd);
$stmt->bindValue(':RAND_SID', $rand_sid);
$stmt->bindValue(':REGID', $regid);
$stmt->execute();
在這種情況下
這裏$ REG在其中添加表的主鍵的最後幾個項目。起初,我認爲這是問題,但是當我清除了',並且'我得到一個無效的id錯誤,我猜測它來自pdo的下一次執行。請幫助,因爲這個錯誤真的讓我失望完成這個項目爲我的客戶。
我的猜測是'$ rand_sid'或'$ regid'沒有值。 – Robbert
'var_dump($ rand_sid);'顯示什麼? –
int(445737646)string(3)「872」是我從var_dump或$ rand_sid和$ regid得到的。 – NSaid