2015-09-17 49 views
-1
$user = DB::update('update users set name = '100' where id = ?', $id); 
    print_r($id); 

$id1,當我運行上面我得到如下:Laravel mysql的更新解析錯誤

FatalErrorException在UpdateUsers.php線83:解析錯誤

83號線是$user = DB::update('update users set name = '100' where id = ?', $id);

回答

2

語法錯誤,試試這個。

DB::table('users') 
     -> where('id', $id) 
     -> update(['name' => 100]); 
1

您必須注意您的單引號和單引號,以及您的起始和結尾雙引號。 例如,你不能做到這一點:

$user = 'I have what you call a 'variable' located here'; 

可以,單引號內然而巢雙引號是這樣的:

$user = 'I have what you call a "variable" located here'; 

,或者你可以逃脫這樣的嵌套單引號:

$user = 'I have what you call a \'variable\' located here'; 

因此,對於導致Parse錯誤(這不是DB如何)的行,它應該是這樣的:

避免使用此,因爲它是不是官方Laravel方式,請參見Laravel文檔:

http://laravel.com/docs/4.2/database

$user = DB::update('update users set name = \'100\' where id = ?', $id); 

$user = DB::update('update users set name = "100" where id = ?', $id);