0

I am not getting idea how to create sql views in symfony. Please can anyone help me how to create sql views in symfony.

1 Answer 1

1

first create the test data :

CREATE TABLE T
    (`id` int, `name` varchar(5))
;

INSERT INTO T
    (`id`, `name`)
VALUES
    (1, 'john'),
    (2, 'henry')
;

creat view in Symfony :

$em = $this->getDoctrine()->getManager(); 
$connection = $em->getConnection();
$statement = $connection->prepare("create view View_T as select * from T where id = 1;");
$statement->execute();

then you can use the View_T by Query:

select * from View_T

get the result

| id | name |
|----|------|
|  1 | john |

Details about view you can learn from SQL CREATE VIEW, REPLACE VIEW, DROP VIEW Statements

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

4 Comments

Thank you @IT weiHan, I have understood. But I am unclear in one things.Do I need to run creating view statement every time?
no, view just need create one time and use any time. when you create exist view it'll throw exception.
okay. Thank you I have understood now.Moreover, please could you tell me,How I can change collation of table in symfony. I have this query " ALTER TABLE table_data CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;" .I think I have to run it through doctrine. I am not getting how to do
please ask another question. it'll get more detail.

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.