简体   繁体   English

AS400 上的 Laravel 8 使用带点的 ODBC 表名

[英]Laravel 8 on AS400 using ODBC table names with dots

I am on a project where I need to retrieve information from a table that contains a "."我在一个项目中,我需要从包含“.”的表中检索信息。 in it's name... My query looks like this:在它的名字...我的查询是这样的:

$data['scale'] = DB::connection('odbc')
->table('QS36F."CF.STYL1"')
->select('SSCALE','SINTDE')
->where('STYLE#', 'LIKE', $style.'%')
->get();

Obviously the above is not working and returns显然上面的方法不起作用并返回

SQLSTATE[42000]: Syntax error or access violation: [IBM][System i Access ODBC Driver][DB2 for i5/OS]SQL0113 - Name """CF" not allowed. SQLSTATE[42000]:语法错误或访问冲突:[IBM][System i Access ODBC 驱动程序][DB2 for i5/OS]SQL0113 - 不允许使用名称“”“CF”。 (SQLPrepare[0] at /home/calvin/rpmbuild/BUILD/php-8.0.8/ext/pdo_odbc/odbc_driver.c:203) (SQL: select "SSCALE", "SINTDE" from "QS36F"."""CF"."STYL1""" where "STYLE#" LIKE 1981USD%) (SQLPrepare[0] at /home/calvin/rpmbuild/BUILD/php-8.0.8/ext/pdo_odbc/odbc_driver.c:203)(SQL:从“QS36F”中选择“SSCALE”、“SINTDE”。“”“ CF"."STYL1""" 其中 "STYLE#" LIKE 1981USD%)

I could probably get it to work using a full raw query but if there's anyway to make it work using normal eloquent functions, I would definitely prefer using table() select() where() get() ect ....我可能可以使用完整的原始查询使其工作,但如果无论如何要使用普通的雄辩函数使其工作,我肯定更喜欢使用 table() select() where() get() 等 ....

Any suggestions?有什么建议么?

Ok so I solved this using DB::raw() like this:好的,所以我使用 DB::raw() 解决了这个问题:

$data['scale'] = DB::connection('odbc')
->table(DB::raw('QS36F."CF.STYL1"'))
->select('SSCALE','SINTDE')
->where('STYLE#', 'LIKE', $style.'%')
->get();

At least this way I am not using a full raw query.至少这样我没有使用完整的原始查询。 I hope that will help the next guy that needs to deal with table names containing dots lol我希望这会帮助下一个需要处理包含点的表名的人哈哈

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM