Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

Like you said, not the best way to do it. But here it is:

'select * from destinations where DestinationName="'.$destination."''

// or should also work

"select * from destinations where DestinationName=\"$destination\""

This could open you up to SQL injection, so just be aware.

This is how to do it using a Model file.

$data = Destinations::where(DestinationName, '=' ,$destination);

The most basic model file.

class Destinations extends Eloquent { }

The lower-case, plural name of the class will be used as the table name unless another name is explicitly specified.
Can over write and set name if wanted by adding the following in the class - protected $table = 'db-table-name';

More info and some example code, http://laravel.com/docs/4.2/eloquent#basic-usage

Hope that helps.

Last updated 9 years ago.
0

Thanks for your reply.

Should I pass this though the real escape string then?

0

I have found this to escape variables and it seems to work.

$data = \DB::select(\DB::raw("SELECT * FROM destinations WHERE DestinationName = :destination"), array( 'destination' => $destination));
Last updated 9 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

ottz0 ottz0 Joined 15 Nov 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.