Jump to content


Photo

MySQL set


  • Please log in to reply
2 replies to this topic

#1 johnnyk

johnnyk
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts

Posted 26 June 2006 - 11:00 PM

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?
Rediscover the Web:
<a href="http://www.spreadfir...;t=219"></a><br />

#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 26 June 2006 - 11:05 PM

this method sets the system timezone for the current script, and returns the previous timezone.


<?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;
?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 johnnyk

johnnyk
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts

Posted 27 June 2006 - 02:58 AM

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;
Rediscover the Web:
<a href="http://www.spreadfir...;t=219"></a><br />




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users