PHP/MySQLi: SET lc_time_names and DATE_FORMAT() into a mysqli query?(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 查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PHP/MySQLi:将 lc_time_names 和 DATE_FORMAT() 设置为 mysq


基础教程推荐
- Libpuzzle 索引数百万张图片? 2022-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- 在多维数组中查找最大值 2021-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01