Question

I'm creating a VIEW of a database in smarty. I am little bit confused about where I should create that view.

I have created a view in a class's constructor function. Now I have the problem that I'm using a function of that class through an object of that class... So is it true that each time I call the function, that view is constructed?

Example:

cityview.php:

class city
{
 function city(){ "mysql query of creating view "}
 function allcity()
  { here is some query on view }
 function callcity()
 { here is some query on view }
}

In index.php I call:

$objcity=new city();
$objcity->allcity();
$objcity->callcity();

Is that VIEW created each time I call any function of that class?

If yes then how do I create that view?

Was it helpful?

Solution

You should definitely separate the code for the view from your application code. The database will continue to exist and remember that view even if your application shuts down. The way to create your view outside of PHP is to log into your database using the username and password that your application would use, and execute the code for any tables and views on the database through a client (sorry - don't know mysql well enough to tell you how to do that).

It sounds like you might already have an existing database, so I would talk to whoever is in charge of that DB about how to set up your view. There might be requirements for how to do source control or other release procedures you might need to be aware of.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top