全部博文(2065)
分类:
2010-10-17 10:28:16
PHP处理MSSQL中datetime类型
时间: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 " while($row = mssql_fetch_array($result)) { echo " } |
为啥用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 |
|