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!

 

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

?>

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.

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.

Archived

This topic is now archived and is closed to further replies.

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