问题
I need translate to "pt_br" the currently month and this code are working like a charm on phpmyadmin:
SET lc_time_names = 'pt_BR';
SELECT MONTHNAME(CURDATE()) AS `Mes`
FROM trabalho_v2
Someone may help me use the "SET lc_time_names = 'pt_BR';" on my php code?
<?php
// Show current month
include 'conection.php';
$sql .= "SELECT MONTHNAME(CURDATE()) AS `Mes` FROM trabalho_v2 ";
$busca = mysqli_query($conexao,$sql);
$dados = mysqli_fetch_array($busca);
$mes = $dados['Mes'];
I tried to create a new querie to inject only this stretch but it didn't work:
<?php
// Show current month
include 'conection.php';
$sql = "SET lc_time_names = 'pt_BR';";
$sql .= "SELECT MONTHNAME(CURDATE()) AS `Mes` FROM trabalho_v2 ";
$busca = mysqli_query($conexao,$sql);
$dados = mysqli_fetch_array($busca);
$mes = $dados['Mes'];
回答1:
These are two separate queries. You can't concatenate them together. You have to execute them separately.
<?php
// Show current month
include 'conection.php';
$sql = "SET lc_time_names = 'pt_BR'";
mysqli_query($conexao, $sql);
$sql = "SELECT MONTHNAME(CURDATE()) AS `Mes` FROM trabalho_v2";
$busca = mysqli_query($conexao, $sql);
$dados = mysqli_fetch_array($busca);
$mes = $dados['Mes'];
I also strongly encourage you to use OO style:
<?php
// Show current month
include 'conection.php';
$sql = "SET lc_time_names = 'pt_BR'";
$conexao->query($sql);
$sql = "SELECT MONTHNAME(CURDATE()) AS `Mes` FROM trabalho_v2";
$busca = $conexao->query($sql);
$dados = $busca->fetch_array();
$mes = $dados['Mes'];
来源:https://stackoverflow.com/questions/65259094/running-two-sql-queries-on-one-php-page-set-select