2
votes

If i have employee_id with integer (like 1001) alone, am getting the answer

example the code like this ,

   $claimprocess = Employee::find()
                    ->where("employee_id = '1004'  and importcompany_id = 1")
                    ->andwhere(" status != 'Deleted' and relationship = 'Self'")
                    ->all();

if i have a employee_id with combination interger and character, am not able get a answer(like E1004),

example code like below,

$claimprocess = Employee::find()
                    ->where("employee_id = 'E1004'  and importcompany_id = 1")
                    ->andwhere(" status != 'Deleted' and relationship = 'Self'")
                    ->all();

When I execute this code, am getting error like below

Exception (Database Exception) 'yii\db\Exception' with message 'SQLSTATE[42S22]: Column not found: 1054 Champ 'E1004' inconnu dans where clause The SQL being executed was: SELECT * FROM employee WHERE (employee_id = E1004 and importcompany_id = 1) AND ( status != 'Deleted' )'

UPDATED:

actually am getting that value(E1004) from another variable, I use the variable instead of value, for understanding purpose I have used a value there in my question

3
employee_id = E1004 it need to be employee_id = 'E1004' - Noman

3 Answers

3
votes

You need to enclose your employee_id value i.e. E1004 within quotes its because it contains string literals. So your query looks like a

->where("employee_id = 'E1004'  and importcompany_id = 1")
1
votes

String literals in SQL are denoted with single quotes ('). Without them, the database would interpret E1004 as a column name, and fail the query, since your table doesn't have such a query.

$claimprocess = Employee::find()
                ->where("employee_id = 'E1004'  and importcompany_id = 1")
                ->andwhere(" status != 'Deleted' and relationship = 'Self'")
                ->all();
0
votes

You need to pass the value correctly , as if now you are not passing the value correctly , hence Yii is not generating Sql query correctly. You can pass second parameter to to where clause

    $claimprocess = Employee::find()
                        ->where("employee_id = ':employee_id'  and importcompany_id = 1" , array(':employee_id'=>'E1004'))
                        ->andwhere(" status != 'Deleted' and relationship = 'Self'")
                        ->all();