Name of the months in Portuguese and English

6

In the site where I work, I use the following query to display in Portuguese the dates that are stored in the database:

$conn->exec("SET lc_time_names = 'pt_PT'");

However, I discovered that the site will become bilingual (Portuguese and English) and I need to show dates in both languages. How should I proceed?

    
asked by anonymous 25.02.2014 / 17:34

2 answers

5

To solve this, create a page called index.php , inside it, you will have language options, only flags of each country for example.

You will then have a choice, depending on the choice you will be redirected to the same page but with a different parameter, this code could be used in index.php eg

<a href=pagina_inicial.php?lang=pt_PT >Português</a>
<a href=pagina_inicial.php?lang=en_US >Inglês</a>

And then inside your "file that connects to bd" from which you posted the code in your question, it would work like this:

$lang = $_GET['lang'];
if ($lang == "pt_PT")
  $conn->exec("SET lc_time_names = 'pt_PT'");
else
  $conn->exec("SET lc_time_names = 'en_US'");

You may be wondering " Why did not I just do it this way? :"

$lang = $_GET['lang'];
$conn->exec("SET lc_time_names = '".$lang."'");

Because it would become a highly vulnerable target for SQL Injection attacks , so it would be very insecure ( never use user-uploadable variables within SQL )

In this way I told you, you can know what language the user wants, at the moment of executing his command, via a parameter that he sent when choosing which language on page index.php .

    
25.02.2014 / 18:09
-3

Use this

mysql_query('SET lc_time_names = "pt_BR"');
    
25.02.2014 / 18:28