Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/243.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel:语法错误或访问冲突_Php_Laravel 4 - Fatal编程技术网

Php Laravel:语法错误或访问冲突

Php Laravel:语法错误或访问冲突,php,laravel-4,Php,Laravel 4,尝试插入文件“image”和文本字段“desc”时出现奇怪错误 刀片 数据库编写器 public function uploadImage(array $input) { $title = $this->title->find($input['title-id']); $name = str_random(25); $insert = array('local' => asset('assets/images/'.

尝试插入文件“image”和文本字段“desc”时出现奇怪错误

刀片

数据库编写器

public function uploadImage(array $input)
    {   
        $title = $this->title->find($input['title-id']);
        $name  = str_random(25);
        $insert = array('local' => asset('assets/images/'.$name.'.jpg'), 
                        'desc' => $input['desc'], 
                        'title_id' => $input['title-id']);

        $this->images->saveTitleImage($input, $name);
        $this->dbWriter->compileInsert('images', $insert)->save();

        Event::fire('Titles.Modified', array($input['title-id']));
    }
错误:

Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'desc,title_id) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE local = values(local), d' at line 1 (SQL: INSERT INTO images (local,desc,title_id) VALUES (/assets/images/o00U6rVZPDbkkKUHjDWajHYUO.jpg, sdsd, 1) ON DUPLICATE KEY UPDATE local = values(local), desc = values(desc), title_id = values(title_id))

您不应该使用desc作为列名,因为它是MySQL中的保留关键字

若要修复此问题,只需更改列名称(例如,说明)并将$insert更改为:

$insert=array('local'=>asset('assets/images/'.$name..jpg'),
'description'=>$input['desc'],
'title_id'=>$input['title-id'])


你可以阅读更多关于MySQLa保留关键字的信息

你不应该使用desc作为列名,因为它是mysql中的保留关键字,请阅读更多omg我从来都不知道我这么多年来一直在试图找出它,我们知道更改它是否解决了问题:)很高兴我能提供帮助。我写了一个答案,这样问题就不会一直没有答案——如果你愿意,你可以接受:)
public function uploadImage(array $input)
    {   
        $title = $this->title->find($input['title-id']);
        $name  = str_random(25);
        $insert = array('local' => asset('assets/images/'.$name.'.jpg'), 
                        'desc' => $input['desc'], 
                        'title_id' => $input['title-id']);

        $this->images->saveTitleImage($input, $name);
        $this->dbWriter->compileInsert('images', $insert)->save();

        Event::fire('Titles.Modified', array($input['title-id']));
    }
Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'desc,title_id) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE local = values(local), d' at line 1 (SQL: INSERT INTO images (local,desc,title_id) VALUES (/assets/images/o00U6rVZPDbkkKUHjDWajHYUO.jpg, sdsd, 1) ON DUPLICATE KEY UPDATE local = values(local), desc = values(desc), title_id = values(title_id))