Jump to content

Archived

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

johnnyk

MySQL set

Recommended Posts

How would I set something like a timezone or mode in MySQL with PHP?
Mysql.org says to use something like
mysql> SET time_zone = timezone;

But what do you do for PHP? I tried
mysql_query("SET time_zone = timezone");
but that didn't work.

While we're at it, what does it mean to set something as GLOBAL?

Share this post


Link to post
Share on other sites
this method sets the system timezone for the current script, and returns the previous timezone.

[code]

<?php
    function setTimezone($timezone)
    {
        $oldTz = getenv('TZ');
        putenv('TZ=' . $timezone);
        return $oldTz;
    }
?>Sample usage:

Highlight: PHP<?php
    $newTz = 'Australia/Adelaide';
    $oldTz = setTimezone($newTz);

    echo "The old timezone was " . $oldTz . " and the new timezone is " . $newTz;
?>
[/code]

Share this post


Link to post
Share on other sites
But that doesn't affect MySQL's NOW()

I'm talking about
[a href=\"http://dev.mysql.com/doc/refman/5.0/en/time-zone-support.html\" target=\"_blank\"]http://dev.mysql.com/doc/refman/5.0/en/tim...ne-support.html[/a]

How do I set MySQL's timezone in PHP. The above page says you should use
mysql> SET time_zone = timezone;
but how do you do that in PHP?

Also, what is the difference between that and
mysql> SET GLOBAL time_zone = timezone;

Share this post


Link to post
Share on other sites

×

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.