Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

mysql - PHP/MySQLi: SET lc_time_names and DATE_FORMAT() into a mysqli query?

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

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..

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

Thanks!!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
$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();
        }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...