Jump to content

How to get right timezon when using NOW() ?


3D-kreativ

Recommended Posts

I do? I thought it was a difference between

 

$res = $mysqli->query($query) or die("Could not query database");

and

$res = $mysqli->multi_query($query) or die("Could not query database");

 

Instead of guessing how you mean, I preciate if you write the correct line of code to write this info the the table. Thanks!

 

Link to comment
Share on other sites

Thanks, but I still have some problem with the second query. I get error message: unexpected T_STRING. I guess it have to do about " or '. I have tested all kinds of combinations, but still same error.

 

Preciate some help so that we can close this post! :)

 

<?php

require_once('config.php');

$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE); 

$mysqli->query('SET time_zone = "Europe/Stockholm"');

$mysqli->query('INSERT INTO 'tracker' (
'id' ,
'ip' ,
'date' ,
'status' ,
'userAgent'
)
VALUES (
NULL , '10.10.10.10', NOW() , '10101', 'nothing');

$mysqli->close();

?>

Link to comment
Share on other sites

You will find that if you use double-quotes as the initial and final quotes when writing a query string that you will be better off because you can then put single-quotes and php variables directly into the query string.

 

Also, table and column names are not enclosed in single-quotes as that would make them strings instead of table and column names.

Link to comment
Share on other sites

You will find that if you use double-quotes as the initial and final quotes when writing a query string that you will be better off because you can then put single-quotes and php variables directly into the query string.

True, as long as you're careful... unexpected variable interpolation has caused many a bug.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.