PHP/MySQLi:将 lc_time_names 和 DATE_FORMAT() 设置为 mysqli 查询? [英] PHP/MySQLi: SET lc_time_names and DATE_FORMAT() into a mysqli query?

查看:22
本文介绍了PHP/MySQLi:将 lc_time_names 和 DATE_FORMAT() 设置为 mysqli 查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I use the next code to retrieve data from a table in the database:

$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();
    }

如您所见,同时我使用 DATE_FORMAT() MySQL 函数将生日"列中的日期格式化为更友好的显示.现在,我想用西班牙语显示月份的全名,所以我想在查询中插入 SET lc_time_names = 'es_ES' ..

Like you can see, at the same time I format the date from the 'birthdate' column to a more friendly display using the DATE_FORMAT() MySQL function. Now, I want to display the month full names in Spanish, so I want to insert SET lc_time_names = 'es_ES' into the query..

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

How can I do it??? Can I add SET lc_time_names to the $check_sql variable??

谢谢!!

推荐答案

$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();
        }

这篇关于PHP/MySQLi:将 lc_time_names 和 DATE_FORMAT() 设置为 mysqli 查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆