Welcome Guest, Not a member yet? Register   Sign In
Model query function not working with bound parameters

This function works if I hard code the values at the bottom of the query. I can confirm that the values are being passed via the parameters. But when I put in the question marks, it stops working. Am I making some foolish error?

function get_this_vehicle_info($ad_id, $user_id)

  $sql = "SELECT
      users.id AS user_id,
      ads.id AS ad_id,
      FROM ads, vehicle_images, users, vehicle_type, vehicle_make, vehicle_model
      WHERE ads.vehicle_type = vehicle_type.id AND
      ads.vehicle_make = vehicle_make.id AND
      ads.vehicle_model = vehicle_model.id AND
      vehicle_images.fk_ad_id = ads.id AND
      ads.id   = ? AND
      users.id  = ?";

   //$query = $this->db->query($sql, array('ads.id', 'users.id'));
   $query = $this->db->query($sql, array('ad_id', 'user_id'));

   if($query->num_rows() > 0)
    return $query;
    return FALSE;  

Incidentally, the query returns zero rows, not an error.

See what it outputs.
echo $this->db->last_query();

Shouldn't it be
$query = $this->db->query($sql, array($ad_id, $user_id));

Indeed that worked. I knew it was a stupid mistake.

Theme © iAndrew 2016 - Forum software by © MyBB