[eluser]TheFuzzy0ne[/eluser]
Exactly. There's no difference, although there may be a slight difference in performance, and as you pointed out, query bindings can only be used for values, not field/table names. Personally, I think the second version looks cleaner. Also, AR gives you more flexibility when it comes to building more complex statements. Sure, a lot of old-school, hardcore programmers build seriously complex SQL queries for breakfast, but I just don't have the time, knowledge or patience, so for me, unless It's something that AR can't do, AR wins hands down every time.
However, an arguably better way of coding your first function would be like this:
Code:
function checkItem ($table, $column, $value)
{
$result = $this->db->query("
SELECT *
FROM `$table`
WHERE ? = ?",
array($column, $value)
);
//Check for a result
if($result->num_rows() > 0)
return TRUE;
else
return FALSE;
}
Yes, I may have complicated it slightly by getting rid of the variable, but the point is, the $table variable is used in the query, as it doesn't really need escaping. Of course, you should probably validate it anyway with a simple regex to ensure if only contains a certain set of characters. Or of course, just use $this->db->escape().