使用中發(fā)現,如果數據庫中查找到數據可以正常運行,沒有查找到符合條件的數據會直接報錯。
$result=$db->select('id')->from('collect_device')->where("unique_identification_number= $fromid ")->single();
echo $result;
報什么錯誤提示?
Press Ctrl-C to quit. Start success.
1PDOException: SQL:SELECT id FROM collect_device
WHERE unique_identification_number= user SQLSTATE[42S22]: Column not found: 1054 Unknown column 'user' in 'where clause' in C:\phpStudy\PHPTutorial\WWW\kaiwu\vendor\GatewayWorker-for-win\Applications\YourApp\Connection.php:1774
Stack trace:
process C:\phpStudy\PHPTutorial\WWW\kaiwu\vendor\GatewayWorker-for-win\Applications\YourApp\start_businessworker.php terminated and try to restart
報了這一堆
SELECT id FROM collect_device WHERE unique_identification_number= user 語句感覺有點奇怪 這個 user 是什么???
unique_identification_number 這個是int型字段string字段類型?
$result=$db->select('id')->from('collect_device')->where("unique_identification_number= '{$fromid}' ")->single(); 這樣子寫語句,應該不會報錯了
沒有報錯了,多謝。因為我在代碼里那個位置添的是$fromid,所以沒加''.我直到現在也不是很明白,我加的$fromid確實是個變量。按照你說的問題確實解決了,萬分感謝