<?php  $conn=.............  function GetNowTime(){
    $rvt=mysql_query("select now() as svTime",$conn);
    $rt=mysql_fetch_object($rvt);
    return $rt->svTime;
    mysql_free_result($rvt);
    mysql_close($conn);
  }
  echo GetNowTime()   //不能获取mysql 服务器的当前时间,这个方法对吗?
?>

解决方案 »

  1.   

    mysql的当前时间函数为now();
    php的当前时间函数为date();
      

  2.   

    想用 php 获取 mysql 服务器的时间,而不是 php 所在服务器的时间。
      

  3.   


    mysql_connect('localhost', 'root', '111111');
    function GetNowTime()
    {
        $rvt = mysql_query("SELECT NOW() AS svTime"); 
        $rt  = mysql_fetch_object($rvt);
        return $rt->svTime;
    }
    echo GetNowTime();这样就可以了  return后面的都不执行了,不需要了,mysql连接在文件结尾会自动释放
      

  4.   


    你写的函数里面的 $conn 是个空变量,所以函数没有连接上数据库,导致取不到值你可以在函数里面 global $conn; 就可以了 // $conn 在函数外创建的数据库连接