我正在學習如何運行原始SQL查詢並停留在UPDATE操作。Laravel DB :: update不工作,什麼都不做,沒有任何錯誤
我有路線INSERT:
Route::get('/insert', function(){
DB::insert('insert into posts (title, content) values (?, ?)', ['PHP with Laravel', 'Just testing']);
return 'after insert';
});
和路由的選擇:
Route::get('/read', function(){
$results = DB::select('select * from posts');
return var_dump($results);
});
SELECT查詢之後,我看到:
/home/pavel/www_mysite/TestLaravel/routes/web.php:31:
array (size=1)
0 =>
object(stdClass)[239]
public 'id' => int 11
public 'title' => string 'PHP with Laravel' (length=16)
public 'content' => string 'Just testing' (length=12)
public 'created_at' => null
public 'updated_at' => null
public 'is_admin' => int 0
而且至少UPDATE查詢:
Route::get('/update', function(){
DB::update('update posts set title = "Nothing here"');
});
之後,查詢新的SELECT查詢顯示相同的數據,並在PHPPgAdmin我沒有發現變化。我安裝了LaravelDebugBar,並可能在瀏覽器的底部看到INSERT和SELECT查詢的頁面,但在UPDATE查詢的頁面上看不到它。我不知道,錯誤在哪裏。
我改變雙引號後使用如下這樣的單引號來得到它: 'Route :: get('/ update',function(){ DB :: update('update posts set title = \' \'); });' 但爲什麼查詢不使用雙引號? – brunen9
我安裝了MySQL,並嘗試相同的查詢,他們只是工作。 INSERT到MySQL數據庫使用雙引號。 – brunen9