2

I have a MySQL query which selects column based on the replace string values passed to a column

SELECT * FROM Table WHERE REPLACE(column_name, '.', '') = 'value';

In the above query i remove dot values from the column_name of the table and I pass values with out dots and it works fine.

Now i need to make this query to work in Yii2 query

I have a query in Yii2 like below,

$Table= Table::findOne([ column_name => \Yii::$app->request->post('value')]);

How can i make the first query condition work in Yii2 query?

2 Answers 2

2

Use Like

$Table= Table::find()
      ->where(["REPLACE(column_name, '.', '')" => \Yii::$app->request->post('value')])
      ->one();

Refer Yii2 DB Query Builder Guide

Sign up to request clarification or add additional context in comments.

Comments

1

a simple way is the use of string format in where condition

  $Table= Table::find()->where("REPLACE(column_name, '.', '') = 'value'")->one();

you can find useful sample in this guide

https://www.yiiframework.com/doc/guide/2.0/en/db-query-builder

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.