NinjaCat
NinjaCat

Reputation: 10204

Kohana: Connecting to DB in different ways

I am new to Kohana, and I would like to know what the difference is between:

$query = DB::select()->from('codes')->where('name', '=', 'PHP')->execute($mydb);

$query = DB::query(Database::SELECT, 'SELECT * FROM codes WHERE name = :name');
$query->param(':name', 'PHP');

Upvotes: 0

Views: 182

Answers (1)

biakaveron
biakaveron

Reputation: 5483

First one is a Query Builder example. Is prefered way to construct your queries, because it uses only standard SQL commands or keywords, so your code will work after changing DB engine. Query Builder automatically escapes all table names, columns and values.

Upvotes: 4

Related Questions