Replacing table name and column name before and after query execution in Yii1.x

305 Views Asked by At

I want to replace table name and field name with some other name before and after execution of queries (CRUD operation).

Let's say I have a DB table - TBL1 with fields (col1, col2, col3) that is basically a users table with fields (id, name, email) but with obfuscated names.

I have SQL queries(select,insert,update) written in Yii controller/model using real names (users, id, name, email) but just before execution these names should get replaced by obfuscated names which are actually present in DB (TBL1, col1, col2, col3).

Similarly, after execution obfuscated names (TBL1, col1, col2, col3) should get replaced by real names (users, id, name, email) for further processing in controller code.

1

There are 1 best solutions below

0
Damian Dziaduch On

Just run basic command like

<?php
Yii::app()->db->createCommand()->execute('ALTER TABLE ...');
// your queries here
Yii::app()->db->createCommand()->execute('ALTER TABLE ...');

This is the easiest way I think