I
I
ilysion_in_life2017-06-14 13:41:37
Yii
ilysion_in_life, 2017-06-14 13:41:37

What is wrong in the query (Yii 1)?

Hello, help me with solving the problem, I have a query to the database (I'm doing it in Yii 1 )
$model = Yii::app()->db->createCommand()->select('id, module_id, key, value')-> from('settings')->
where('module_id=:module_id and key=:key', array(':module_id' => $module_id,
':key' => $key_type))->queryRow();
the query should take the value from the base in the value column with a selection of 2 parameters that are passed in the $module_id, $key_type variables, but my problem is that an error occurs
CDbCommand failed to execute SQL query: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'key='wooUrl'' at line 3. The SQL statement executed was: SELECT `id`, `module_id`, `key`, `value`
FROM `settings`
WHERE module_id=:module_id and key=:key
I can't understand why, how would everything be right or am I blind, please help me poke your finger.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2017-06-14
@ilysion_in_life

I don’t remember yii1 already, but in my opinion it’s like this:

$user = Yii::app()->db->createCommand()
    ->select('id, module_id, key, value')
    ->from('settings')
    ->where('module_id=:module_id', array(':module_id' => $module_id))
    ->andWhere('key=:key', array(':key' => $key_type))
    ->queryRow();

and maybe this is also possible:
$user = Yii::app()->db->createCommand()
    ->select('id, module_id, key, value')
    ->from('settings')
    ->where(array('module_id=:module_id','key=:key'), array(':module_id' => $module_id,
':key' => $key_type))
    ->queryRow();

www.yiiframework.com/doc/api/1.1/CDbCommand#andWhere()
www.yiiframework.com/doc/guide/1.1/en/database.que...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question