Don't use prepared statements in Laravel Eloqu

2019-02-19 11:30发布

问题:

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