0

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

how can I declare something similar to static variable that describes language in that session

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

Community
  • 1
  • 1
shevski
  • 1,012
  • 1
  • 10
  • 32
  • I think you are looking for sessions. http://www.php.net/manual/en/book.session.php – Pekka Dec 19 '10 at 22:49
  • no, I have the session's language i want to make a proper select in sql, but all of my query just append "and idlng=$lng", I would like to store a state in MySQL for that connection that will define that language. – shevski Dec 19 '10 at 22:54

2 Answers2

1

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.

alexn
  • 57,867
  • 14
  • 111
  • 145
  • ok, thanks, if I'll make a stored procedure that is a function of @lng ,I'll get the desired affect of setting a global static @lng? – shevski Dec 19 '10 at 23:05
0

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

greg0ire
  • 22,714
  • 16
  • 72
  • 101