gpt4 book ai didi

php - 无法在 Eloquent/Query Builder 中使用多个占位符

转载 作者:行者123 更新时间:2023-11-29 05:06:01 24 4
gpt4 key购买 nike

我正在使用这个作为我的查询:

$fields = DB::select('select * from ? where form_master_id=?',
[$field->table_name,$field->form_master_id]);

这给了我错误:

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 '? where form_master_id=?' at line 1 (SQL: select * from articles where form_master_id=101)

但是当我检查查询时:select * from articles where form_master_id=101,它在 phpmyadmin 中非常适合我。

最佳答案

您询问的是 Eloquent 或 Query Builder 解决方案,但仅讨论原始查询。

Query Builder 解决方案非常简单:

DB::table($someTable)->where('form_master_id', $formMasterId)->get();

Eloquent 解决方案:

$model = 'App\\' . $someModel;
$model::where('form_master_id', $formMasterId)->get();

关于php - 无法在 Eloquent/Query Builder 中使用多个占位符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48037271/

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