Parameter by name in the query

Asked

Viewed 26 times

0

I have the following appointment

SELECT * FROM myTable WHERE ip = 192.168.1.2

I would like to make a query by sending parameter by name using DB::raw()

$dados = DB::raw("SELECT * FROM myTable WHERE ip = :ip", ["ip" => '192.168.1.2'])

It is possible?

I tried that way but I couldn’t

I want to do so, because if you have a query that repeats again the parameter I do not have to repeat variable

  • What do you really want to do??? I don’t understand ... just answering that you asked that way there not there ... !

  • Instead of using ? by parameter as some name. Example: WHERE id = ? use WHERE id = :id, in some queries I need to repeat this id

  • I understood, but, no \DB::raw doesn’t have that.

  • Etntendi! Beauty, thanks!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.