Chinaunix首页 | 论坛 | 博客
  • 博客访问: 26253687
  • 博文数量: 2065
  • 博客积分: 10377
  • 博客等级: 上将
  • 技术积分: 21525
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-04 17:50
文章分类

全部博文(2065)

文章存档

2012年(2)

2011年(19)

2010年(1160)

2009年(969)

2008年(153)

分类:

2010-10-17 10:28:16

PHP处理MSSQLdatetime类型

时间:2010-10-17

ASP代码

<%

Dim MM_routeros_STRING

'MM_routeros_STRING = "dsn=radius;uid=ebony;pwd=2btqqd6WpETCaK9W"

MM_routeros_STRING = "dsn=radius;uid=sa;pwd=hkebao"

'引入连接DB的数据连接对象ADODB.Connection

Dim Conn

Set Conn = Server.CreateObject("ADODB.Connection")

If Err.Number <> 0  Then

       Set Conn = Nothing

       response.End()

End If

Conn.ConnectionTimeout = 20

Conn.CommandTimeout = 30

Conn.Open MM_routeros_STRING

Dim jifei

Dim jifei_numRows

Set jifei = Server.CreateObject("ADODB.Recordset")

jifei.ActiveConnection = MM_routeros_STRING

jifei.Source = "SELECT top 1 TransTime  FROM dbo.accounting where Type='2' ORDER BY TransTime DESC"

jifei.CursorType = 0

jifei.CursorLocation = 2

jifei.LockType = 1

jifei.Open()

jifei_numRows = 0

if (jifei.eof and jifei.bof) then

response.write("")

response.End

end If

While ((NOT jifei.EOF))

time_stop=(jifei.Fields.Item("TransTime").Value)'2010-10-1 2:57:59

response.write (time_stop)   #打印:2010-10-1 2:57:59 合法的DateTime格式

jifei.MoveNext()

wend

 

 

 

 

 

 

 

PHP代码

$this->load->database();

$sql = "select top 1 times from test";//2010 三月 29 1:38  | 2010 十月 6 12:15

$result = $this->db->query($sql);

$row = $result->row_array();

$row = $result->row();

$time = $row->times;

echo $time;                        //2010 十月 6 12:15

$myServer = "127.0.0.1"; //主机

$myUser = "sa"; //用户名

$myPass = "hkebao"; //密码

$myDB = "hnebony";  //MSSQL库名

      

$s = @mssql_connect($myServer, $myUser, $myPass)or die("Couldn't connect to SQL Server on $myServer");

$d = @mssql_select_db($myDB, $s)or die("Couldn't open database $myDB");

$query = "select top 1 times from test"; 

$result = mssql_query($query);

$numRows = mssql_num_rows($result);

echo "

" . $numRows . " Row" . ($numRows == 1 ? "" : "s") . " Returned

";

while($row = mssql_fetch_array($result))

{

    echo "

  • " . $row["times"] . "
  • ";//2010 十月 6 12:15

    }

     

    为啥用MSSQL在连接PHP的时候遇到了这样的时间Datetime的时候就显示不正常了?

     

    解决办法:

    SQL语句下手

    $this->load->database();

    $sql = "select top 1 convert(char(30),times,20) as times from test";//2010 三月 29 1:38  | 2010 十月 6 12:15

    $result = $this->db->query($sql);

    $row = $result->row_array();

    $row = $result->row();

    $time = $row->times;

    echo $time;                #2010-05-06 12:15:16

     

     

    阅读(1612) | 评论(0) | 转发(0) |
    给主人留下些什么吧!~~