Don't use prepared statements in Laravel Eloquent ORM?

為{幸葍}努か 提交于 2019-12-01 10:22:17

问题


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

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.


回答1:


For anything other than SELECT you can use unprepared()

DB::unprepared($sql);

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();


来源:https://stackoverflow.com/questions/25296029/dont-use-prepared-statements-in-laravel-eloquent-orm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!