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();
}
相关文章