Head back with Php+sqlsrv this non-mainstream combination do not know how to deal with this time the object has no master pointing twos
[0] = = Array
(
[UserId] = 10
[Account] = P6000001
[PassWord] = 123456
[Loginnumber] = 4
[UpdateTime] = DateTime Object
(
)
[Registtime] = DateTime Object
(
)
[EndTime] = DateTime Object
(
)
[Status] = 0
[Createtime] = DateTime Object
(
)
[MachineID] = 135
)
How to convert this time object into a timestamp
Reply to discussion (solution)
First try to convert with the date function
For example, if the data you are reading is in a $r array,
echo Date (' y-m-d h:i:s ', $r [0][' UpdateTime ']);
Look
If not, please post
Echo Serialize ($R);
The results
You should select a record that does have a value
= = = Source
$sqlsrv = new sqlsrv ();
$sql = "Select TOP 1 [updatetime]
, [Registtime]
, [EndTime]
From [User] ";
$stmt = $sqlsrv->select ($sql);
P ($stmt);
echo Date (' y-m-d h:i:s ', $stmt [0][' UpdateTime ']);//This line is not printed
Echo '
';
Echo Serialize ($stmt);
= = = The following is the printed result
Array
(
[0] = = Array
(
[UpdateTime] = DateTime Object
(
)
[Registtime] = DateTime Object
(
)
[EndTime] = DateTime Object
(
)
)
)
A:1:{i:0;a:3:{s:10: "UpdateTime"; O:8: "datetime": 0:{}s:10: "Registtime"; O:8: "datetime": 0:{}s:7: "EndTime"; O:8: " DateTime ": 0:{}}}
The content is not visible after serialization, indicating that your field is empty
You should select fields with data to test
There is data in SQL Server is not empty (in Baidu to the post of people read the time is not friendly I met a DateTime object and with Get_object_vars () is an empty array really do not know how to complete this object)
UserId account PassWord loginnumber updatetime registtime EndTime Status createtime MachineID
P6000001 123456 4 2013-09-27 13:16:44.503 2013-03-21 10:18:37.000 2019-04-19 17:27:53.047 0 2013-04-19 17:27:53.050 135
Put your code out.
Put your code out.
Code on the second floor {SQL Server The type of these three fields is DateTime is not the same as the DateTime in MySQL}
I wrote a connection class
Class sqlsrv{
Public $connect;
function __construct ($host = "(local)", $uid = "sa", $pwd = "123456", $dbname = "Tupoemanager") {
$connectionInfo = Array ("UID" = = $uid, "PWD" = = $pwd, "Database" = $dbname);
$this->connect = Sqlsrv_connect ($host, $connectionInfo);
Sqlsrv_query ("Set names ' UTF8 '");
echo "
}
//select
Function Select ($sql, $affected =2) {
$result = sqlsrv_query ($this->connect, $sql);
//var_dump ($result);
$resultArr = Array ();
if ($affected ==2) {
while ($row =sqlsrv_fetch_array ($result, Sqlsrv_fetch_assoc)) {
$resultArr [] = $row ;
}
}else{
$resultArr = Sqlsrv_fetch_array ($result, SQLSRV_FETCH_ASSOC);
}
Return $RESULTARR;
}
//query
Function Query ($sql) {
return sqlsrv_query ($this->connect, $sql);
}
//
Function affected ($stmt) {
return sqlsrv_rows_affected ($stmt);
}
}
Date_default_timezone_set ("PRC");
when querying with convert () OK
$sql = "Select TOP 1
CONVERT (varchar), Updateti me,120) as UpdateTime
from [User] ";
$stmt = $sqlsrv->select ($sql);