PHP/MySQLi:将SET lc_time_names和DATE_FORMAT()转换成mysqli查询?

Jon*_*han 1 php mysql database mysqli

我使用下一个代码从数据库中的表中检索数据:

$check_sql = 'SELECT personID, name, DATE_FORMAT(persons.birthdate, "%d de %M, %Y"), birthplace, countryID FROM persons WHERE personID = ?';
    if ($stmt->prepare($check_sql)) {
        $stmt->bind_param('i', $pid);
        $stmt->bind_result($personDB, $name, $birthdate, $birthplace, $countryID);
        $stmt->execute();
        $stmt->fetch();
    }
Run Code Online (Sandbox Code Playgroud)

就像你看到的那样,同时我使用DATE_FORMAT()MySQL函数将日期从'birthdate'列格式化为更友好的显示.现在,我想用西班牙语显示月份全名,所以我想插入SET lc_time_names = 'es_ES'查询..

我该怎么做???我可以添加SET lc_time_names到$ check_sql变量吗?

谢谢!!

var*_*tec 5

$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
$mysqli->query("SET lc_time_names = 'es_ES'");
$check_sql = 'SELECT personID, name, DATE_FORMAT(persons.birthdate, "%d de %M, %Y"), birthplace, countryID FROM persons WHERE personID = ?';
        if ($stmt = $mysqli->prepare($check_sql)) {
                $stmt->bind_param('i', $pid);
                $stmt->bind_result($personDB, $name, $birthdate, $birthplace, $countryID);
                $stmt->execute();
                $stmt->fetch();
        }
Run Code Online (Sandbox Code Playgroud)