不要在 Laravel Eloquent ORM 中使用准备好的语句? [英] Don't use prepared statements in Laravel Eloquent ORM?

查看:19
本文介绍了不要在 Laravel Eloquent ORM 中使用准备好的语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以让 Eloquent ORM 运行查询而不使用准备好的语句吗?还是我必须使用 whereRaw()?

Can I have Eloquent ORM run a query without using prepared statements? Or do I have to use whereRaw()?

我需要使用原始查询,因为我正在尝试与 InfiniDB 交互,后者不支持来自 PHP 的准备好的语句.无论如何,所有查询都将使用内部生成的数据,而不是用户输入,因此这不应该是安全问题.

I need to use a raw query because I'm trying to interact with InfiniDB, which lacks support for prepared statements from PHP. At any rate, all queries will be using internally generated data, not user input so it should not be a security issue.

推荐答案

对于 SELECT 以外的任何内容,您可以使用 unprepared()

For anything other than SELECT you can use unprepared()

DB::unprepared($sql);

对于未准备好的 SELECT,您可以通过 getPdo()

For an unprepared SELECT you can use plain PDO query() by getting access to active PDO connection through getPdo()

$pdo = DB::getPdo();
$query = $pdo->query($sql);
$result = $query->fetchAll();

这篇关于不要在 Laravel Eloquent ORM 中使用准备好的语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆