okay, so let me try this again: if we place this data into a variable, then it becomes a string and php datetime objects will choke because it is not a datetime object. We have a string. Why waste code doing what sql will allready do for us? i’d rather format the string as it comes out of the database. Fast, easy, efficient. However, it seems that two DATE_FORMAT commands cannot be used in a single query or the command cannot act upon two columns with one command:
$selQuery = "SELECT DATE_FORMAT (loginDatetime, lastloginDatetime, '%W, %d. %M %Y %H:%i:%S') loginDatetime, lastloginDatetime FROM user_accounts WHERE id = :userID";
this results in a server 500. I don’t know how to use this command effectively on two columns. In fact, i didn’t know how to do this in the first place. I had to answer my own question about setting the region AND formatting the data. I am happy that i figured it out and a bit proud of myself but no back patting. Just happy. Now i want to format both column values but i cannot get it to work.
The login process works as such:
$selQuery = 'SELECT id, username, password, loginDatetime FROM user_accounts WHERE username = :User';
$dbLoginDT = $result['loginDatetime']; //here we store the logintime for entry into the last login time column
if (hash_equals($dbUser, $username) && password_verify($password, $dbPassword)) {
//bla bla user is valid or not
//now we get the hammer out and get to work:
$UpdateDB = 'UPDATE user_accounts SET user_session_id = :userSid, loginDatetime = NOW(), last_loginDatetime = :dbLoginDT WHERE id = :userID';
//dbLoginDT is the variable above: $dbLoginDT = $result['loginDatetime'];
first SET lc_time_names for the following format command or you will get the mysql en-us default
$selQuery = "SELECT DATE_FORMAT (loginDatetime, '%W, %d. %M %Y %H:%i:%S') loginDatetime FROM user_accounts WHERE id = :userID";
$_SESSION['LoginDT'] = $result['loginDatetime'];
**now i need to do the same for last login datetime but i cannot get it to work in one query.**
**i have it working fine with two queries but i'd like to optimize this code to mimize db activity.**
is there a way to execute a date format command on two column values simultaneously? or do i continue with two separate set lc and date format queries?