|
![](/images/resource/spacer.gif) |
|
สอบถาม php 7.1 กับ ms sql ครับ เกี่ยวกับ getdate() |
|
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
รบกวนสอบถามครับ ตามโค๊ดตัวอย่าง ผม echo ค่า stampdatetime ออกมาไม่ได้ครับ รบกวน ด้วยครับ php 7.1
Code (PHP)
$sql_servername = 'DEV-SQL';
$sql_username = 'sa';
$sql_password = '123456789';
$dbname = 'MEMBER';
$connectionInfo = array("Database"=>$dbname, "UID"=>$sql_username, "PWD"=>$sql_password, "CharacterSet" => "UTF-8", "MultipleActiveResultSets"=>true);
$conn = sqlsrv_connect( $sql_servername, $connectionInfo);
$sql = "select getdate() as stampdatetime";
$stmt = sqlsrv_query( $conn, $sql, array(), array("Scrollable"=>"buffered"));
if( $stmt === false){
echo "Error in statement execution."." line : ".__LINE__."<br>";
die( print_r( sqlsrv_errors(), true));
}
$rows = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC);
$stampdatetime = $rows['stampdatetime'];
echo $stampdatetime;
Tag : Mobile, Ms SQL Server 2008, IIS
![](/images/adv.jpg?v=1001)
|
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2018-01-09 11:50:54 |
By :
slingxer1156 |
View :
593 |
Reply :
4 |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
Code (PHP)
$conn = sqlsrv_connect( $sql_servername, $connectionInfo);
if( !$conn ) die( print_r( sqlsrv_errors(), true)); // connect ได้หรือเปล่า
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2018-01-09 14:23:28 |
By :
Chaidhanan |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
connect ได้ปกติครับ และ ฟิลด์ อื่นแสดงค่าได้ปกติ แต่ ถ้าเป็นฟิลด์ ที่เป็น datetime พังครับ ผมลอง var_dump ค่าออกมา ตัวอย่างซัก 2 ฟิลด์ นะครับ ค่าที่ได้
ฟิลด์ที่เป็น varchar จะได้ = string(10) "0012000778"
ส่วนฟิลด์ที่เป็น datetime จะได้ = object(DateTime)#2 (3) { ["date"]=> string(26) "2018-01-10 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(12) "Asia/Bangkok" }
เป็น อาเรย์ ยาวๆ ออกมาเลยครับ ซึ่ง ถ้าต้องไปแก้ คิวรี่โดยการ convert อันนี้แก้เยอะมากครับ มี stored procedure ด้วย แต่ถ้าแก้ตอน fetch ได้ก็ น่าจะ สะดวกกว่า ผมสงสัยว่า ตอน fetch ค่าต้องมีการ convert หรือเปล่าครับ php เวอร์ชั่น เก่าไม่เป็นครับ เพิ่งมาเจอใน 7.1 นี่แหละครับ โค๊ดเดิม ที่ใช้อยู่ ผม อัพเกรดเวอร์ชั่นครับ
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2018-01-10 14:30:02 |
By :
slingxer1156 |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
ได้แล้วครับ แก้ connection โดยการเพิ่ม "ReturnDatesAsStrings" => true เข้าไปครับ
$connectionInfo = array("Database"=>$dbname, "UID"=>$sql_username, "PWD"=>$sql_password, "CharacterSet" => "UTF-8", "ReturnDatesAsStrings" => true, "MultipleActiveResultSets" => true );
ขอบคุณ ครับ
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2018-01-10 14:47:45 |
By :
slingxer1156 |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
มีคำถามเพิ่มครับ ในฟิลด์ ข้อมูลเป็น 0.00 แต่พอ fetch ค่าออกมา ได้เป็น
.00
อันนี้แก้ยังไงครับ ใครพอรู้บ้าง พอดีเพิ่งมาหัดเล่น php7 ครับ เลยเจอปัญหาครับ
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2018-01-10 15:18:07 |
By :
slingxer1156 |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
|
|
|
![](/images/digitalocean-banner.jpg)
|
Load balance : Server 05
|