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

[eluser]zulubanslee[/eluser]
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?


Code:
function get_this_vehicle_info($ad_id, $user_id)
{

  $sql = "SELECT
      users.id AS user_id,
      ads.id AS ad_id,
      ads.year,
      ads.price,
      ads.mileage,
      ads.transmission,
      ads.description,
      ads.city,
      ads.state,
      ads.zip_code,
      ads.phone,
      vehicle_type.vehicle_type,
      vehicle_make.vehicle_make,
      vehicle_model.vehicle_model,
      vehicle_images.image_name
      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;
   else
    return FALSE;  
}
#2

[eluser]zulubanslee[/eluser]
Incidentally, the query returns zero rows, not an error.
#3

[eluser]CroNiX[/eluser]
See what it outputs.
Code:
echo $this->db->last_query();
#4

[eluser]CroNiX[/eluser]
Shouldn't it be
Code:
$query = $this->db->query($sql, array($ad_id, $user_id));
#5

[eluser]zulubanslee[/eluser]
Indeed that worked. I knew it was a stupid mistake.




Theme © iAndrew 2016 - Forum software by © MyBB