开发者

static and globally filter in sql select statement

relating to implementation of What are best practices for multi-language database design?

how can I declare something similar to static variable t开发者_JAVA技巧hat describes language in that session

now I use a static and globally variable/Session in PHP and concatenation of it to the query string.


MySQL supports a local, session and global variables. You want to use session.

To set a session variable, simply:

SET @key = 'value'

All session variables are prefixed with a '@'.

Session variables goes out of scope when the connection is terminated.

In your case, you will still need to AND your queries, like:

SELECT * FROM pages WHERE lang = @lang

You cannot automatically do this.

More info in the documentation.


Using an ORM like doctrine would allow you to do things like this using events. See the method preDqlSelect() on this page: http://www.doctrine-project.org/projects/orm/1.2/docs/manual/event-listeners/en

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜