Narayan Ghimire
Narayan Ghimire

Reputation: 173

How to create Database sql views in symfony

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

Upvotes: 0

Views: 1086

Answers (1)

Wei Lin
Wei Lin

Reputation: 3791

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

Upvotes: 1

Related Questions