Jump to content

SQL Query errors


macjo

Recommended Posts

Hey everyone,

Here is my problem. I doing some queries to the database but I keep getting stuck on certain queries.
 For example:

$query = new DbQuery();
        $query->select('id_product')
                ->from('product_attribute')
                ->where('id_product_attribute ='.$id);

        return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);

This will return me the correct id_product.

but if I modify it to search by reference. For example

        $query = new DbQuery();
        $query->select('id_product')
            ->from('product_attribute')
            ->where('reference ='.$reference);

        return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);

This query keeps returning FALSE. I can't seem to understand why.

I've used executeS and getRow. Both would fit my queries since there would only be one correct row being returned (all my references are unique) but it doesn't seem to be the case. Every query that uses another field then the id seems to always return false. I've tried it with different tables.

I know that there's something wrong with my code but I can't seem to find the problem.
Happy to hear from anyone with an idea :)

Cheers

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...