php - Yii 1.1 How to get raw query from queryBuilder
Get the solution ↓↓↓I have YII PHP code below:
$query = Yii::app()->db->createCommand()->select('id,email')
->from('users')
->where('id=:id', array(':id'=>2))
->getText();
echo "<pre>"; print_r($query); echo "</pre>"; exit;
Output:
SELECT `id`, `email`
FROM `users`
WHERE id=:id
Expected Result:
SELECT `id`, `email`
FROM `users`
WHERE id=2
Please help
Answer
Solution:
I think you can try this way:
$query = Yii::app()->db->createCommand()->select('id,email')
->from('users')
->where('id=:id', array(':id'=>2))
->getText();
var_dump($query->params);
var_dump($query->text);
If there are any parameters to be bound to the query, they can be retrieved via the CDbCommand::params property.
Check please the documentation
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: unable to determine current zabbix database version: the table "dbversion" was not found.
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.