gpt4 book ai didi

php - laravel 抛出 mysql 错误

转载 作者:行者123 更新时间:2023-11-29 00:15:34 25 4
gpt4 key购买 nike

出于某种原因,当我尝试运行以下代码时,Laravel 给我一个 SQL 错误。我得到的错误如下:

SQLSTATE[42000]: Syntax error or access violation: 1064 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 'from `homes` where `Company` = ?' at line 1 (SQL: select from `homes` where `Company` = Abbeyfield)

代码如下:

<?php

class AnalysisController extends BaseController {

public function getSelect(){

//current USER
$current_user = Auth::user();

echo $relevant_homes = Home::where('Company', '=', $current_user->company_name)->get(array());

/*
return View::make('analysis.select')->with('current_user', $current_user);
*/
}
}
?>

有什么想法吗?

最佳答案

get() 中移除空白数组。您的代码生成了以下 sql:

select from `homes` where `Company` = Abbeyfield

缺少 * 或任何字段,因为您传递了一个空白 array。应该是:

$relevant_homes = Home::where('Company', '=', $current_user->company_name)->get();

或者传递数组中的一些字段名进行选择,例如:

// Assumed that, id and Company as available fields in the table
$relevant_homes = Home::where('Company', '=', $current_user->company_name)->get(array('id', 'Company'));

关于php - laravel 抛出 mysql 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23089214/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com