久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<i id='T6r88'><tr id='T6r88'><dt id='T6r88'><q id='T6r88'><span id='T6r88'><b id='T6r88'><form id='T6r88'><ins id='T6r88'></ins><ul id='T6r88'></ul><sub id='T6r88'></sub></form><legend id='T6r88'></legend><bdo id='T6r88'><pre id='T6r88'><center id='T6r88'></center></pre></bdo></b><th id='T6r88'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='T6r88'><tfoot id='T6r88'></tfoot><dl id='T6r88'><fieldset id='T6r88'></fieldset></dl></div>
  • <small id='T6r88'></small><noframes id='T6r88'>

      <legend id='T6r88'><style id='T6r88'><dir id='T6r88'><q id='T6r88'></q></dir></style></legend>
    1. <tfoot id='T6r88'></tfoot>

          <bdo id='T6r88'></bdo><ul id='T6r88'></ul>

        PHP sqlsrv 驅動程序和 PDO 驅動程序之間的數據類型

        Data type differences between PHP sqlsrv driver and PDO driver(PHP sqlsrv 驅動程序和 PDO 驅動程序之間的數據類型差異)

          <tbody id='U9TYH'></tbody>

          <bdo id='U9TYH'></bdo><ul id='U9TYH'></ul>

              1. <i id='U9TYH'><tr id='U9TYH'><dt id='U9TYH'><q id='U9TYH'><span id='U9TYH'><b id='U9TYH'><form id='U9TYH'><ins id='U9TYH'></ins><ul id='U9TYH'></ul><sub id='U9TYH'></sub></form><legend id='U9TYH'></legend><bdo id='U9TYH'><pre id='U9TYH'><center id='U9TYH'></center></pre></bdo></b><th id='U9TYH'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='U9TYH'><tfoot id='U9TYH'></tfoot><dl id='U9TYH'><fieldset id='U9TYH'></fieldset></dl></div>
                <tfoot id='U9TYH'></tfoot>
                <legend id='U9TYH'><style id='U9TYH'><dir id='U9TYH'><q id='U9TYH'></q></dir></style></legend>

                <small id='U9TYH'></small><noframes id='U9TYH'>

                  本文介紹了PHP sqlsrv 驅動程序和 PDO 驅動程序之間的數據類型差異的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  這里我使用的是 sqlsrv:

                  $conn = sqlsrv_connect("192.168.1.102,1433", array("Database"=>"RF_User", "UID"=>"rfo-gcp", "PWD" => ""));
                  
                  $tsql = "SELECT birthdate FROM tbl_rfaccount WHERE id = ?";
                  
                  $stmt = sqlsrv_query($conn, $tsql, array("test"));
                  
                  $result = sqlsrv_fetch_array($stmt);
                  
                  var_dump($result);
                  

                  結果:array(2) { [0]=>object(DateTime)#1 (3) { ["date"]=>string(26) "2020-04-19 20:40:00.000000" ["timezone_type"]=>int(3) [時區"]=>string(3) "UTC" } ["birthdate"]=>object(DateTime)#1 (3) { ["date"]=>string(26) "2020-04-19 20:40:00.000000" ["timezone_type"]=>int(3) [時區"]=>string(3) "UTC" } }

                  這里我使用的是PDO:

                  $conn = new PDO("sqlsrv:Server=192.168.1.102,1433; Database=RF_User;", "rfo-gcp", "");
                  
                  $tsql = "SELECT birthdate FROM tbl_rfaccount WHERE id = cast(? as varchar(13))";     
                  
                  $stmt = $conn->prepare($tsql);
                  
                  $stmt->execute(array("test"));
                  
                  $result = $stmt->fetch(PDO::FETCH_ASSOC);
                  
                  var_dump($result);
                  

                  結果:array(1) { ["birthdate"]=>string(19) "2020-04-19 20:40:00" }

                  如果您注意到,我必須在 PDO 代碼上使用 cast(? as varchar(13)).沒有它不會返回任何行.在 sqlsrv 上,我不必使用 CAST() 函數.為什么是這樣?另外,數據庫上的id列是一個BINARY(13),那么為什么我要強制轉換idvarchar 而不是 binary(使用二進制轉換它也找不到行)?

                  If you notice, I had to use cast(? as varchar(13)) on the PDO code. Without it would not return any row. On the sqlsrv I didn't have to use the CAST() function. Why is this? Also, the id column on the database is a BINARY(13), so why do I have to cast the id to varchar and not to binary (with binary cast it also doesn't find the row)?

                  推薦答案

                  為什么日期和時間值的返回方式不同?

                  其實這只是一個設定.

                  當您使用 PDO_SQLSRV(正如 在文檔中提到),日期和時間類型(smalldatetime、datetime、date、time、datetime2 和 datetimeoffset)默認以字符串形式返回.PDO::ATTR_STRINGIFY_FETCHES 和 PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE 屬性都沒有任何影響.為了將日期和時間類型檢索為 PHP DateTime 對象,請將連接或語句屬性 PDO::SQLSRV_ATTR_FETCHES_DATETIME_TYPE 設置為 true(默認為 false).

                  When you use PDO_SQLSRV (as is mentioned in the documentation), date and time types (smalldatetime, datetime, date, time, datetime2, and datetimeoffset) are by default returned as strings. Neither the PDO::ATTR_STRINGIFY_FETCHES nor the PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE attribute has any effect. In order to retrieve date and time types as PHP DateTime objects, set the connection or statement attribute PDO::SQLSRV_ATTR_FETCHES_DATETIME_TYPE to true (it is false by default).

                  當您使用 SQLSRV 驅動程序時(同樣來自 文檔)、smalldatetime、datetime、date、time、datetime2 和 datetimeoffset 類型將作為 PHP DateTime 對象返回.可以通過在連接字符串或語句級別設置 'ReturnDatesAsStrings' 選項來更改此行為.

                  When you use SQLSRV driver (again from the documentation), smalldatetime, datetime, date, time, datetime2, and datetimeoffset types will be returned as PHP DateTime objects. This behaviour can be changed by setting the 'ReturnDatesAsStrings' option in the connection string or at the statement level.

                  $conn = sqlsrv_connect(
                     "192.168.1.102,1433", 
                      array(
                         "ReturnDatesAsStrings"=>true,
                         "Database"=>"RF_User", 
                         "UID"=>"rfo-gcp", 
                         "PWD" => ""
                     )
                  );
                  

                  請注意,某些功能取決于 SQL Server 的 PHP 驅動程序版本.

                  Note that some of the features depend on the version of PHP Driver for SQL Server.

                  如何轉換參數值?

                  在語句中使用 CAST()CONVERT() 函數并將參數值與字符串值綁定應該可以工作.當然,您可以在綁定參數時指定參數數據類型.

                  Using CAST() and CONVERT() functions in the statement and binding parameter value with string value should work. Of course, you can specify the parameter data type, when you bind a parameter.

                  對于 PDO_SQLSRV,您應該為 PDOStatement::bindParam().

                  對于 SQLSRV,您可以使用擴展的 $params syntax 指定 SQL Server數據類型,當您調用 sqlsrv_query()sqlsrv_execute() 時.

                  For SQLSRV you may use the extended $params syntax to specify the SQL Server data type, when you make a call to sqlsrv_query()sqlsrv_execute().

                  我可以重現這個問題(PHP 7.1.12、PHP Driver for SQL Server 4.3.0+9904、SQL Server 2012),解決方案是使用:

                  I'm able to reproduce this issue (PHP 7.1.12, PHP Driver for SQL Server 4.3.0+9904, SQL Server 2012) and the solution is to use:

                  $params = array($id, SQLSRV_PARAM_IN, null, SQLSRV_SQLTYPE_BINARY);          // SQLSRV
                  $stmt->bindParam(1, $id, PDO::PARAM_LOB, null, PDO::SQLSRV_ENCODING_BINARY); // PDO_SQLSRV 
                  

                  表格:

                  CREATE TABLE tbl_rfaccount (id binary(13), birthdate datetime)
                  INSERT INTO tbl_rfaccount (id, birthdate) VALUES (CONVERT(binary(13), 'Test'), GETDATE())
                  

                  PHP:

                  <?php
                  ...
                  
                  // 
                  $id = "Test";
                  
                  // SQLSRV
                  $tsql = "SELECT birthdate FROM tbl_rfaccount WHERE id = ?";
                  $params = array($id, SQLSRV_PARAM_IN, null, SQLSRV_SQLTYPE_BINARY);
                  $stmt = sqlsrv_query($conn, $tsql, $params);
                  if ($stmt === false) {
                      echo "Error (sqlsrv_query): ".print_r(sqlsrv_errors(), true);
                      exit;
                  }
                  $result = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC);
                  var_dump($result);
                  
                  // PDO_SQLSRV
                  $tsql = "SELECT birthdate FROM tbl_rfaccount WHERE id = ?";     
                  $stmt = $conn->prepare($tsql);
                  $stmt->bindParam(1, $id, PDO::PARAM_LOB, null, PDO::SQLSRV_ENCODING_BINARY);
                  $stmt->execute();
                  $result = $stmt->fetch(PDO::FETCH_ASSOC);
                  var_dump($result);
                  
                  ...
                  ?> 
                  

                  這篇關于PHP sqlsrv 驅動程序和 PDO 驅動程序之間的數據類型差異的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  MySQLi prepared statement amp; foreach loop(MySQLi準備好的語句amp;foreach 循環)
                  Is mysqli_insert_id() gets record from whole server or from same user?(mysqli_insert_id() 是從整個服務器還是從同一用戶獲取記錄?)
                  PHP MySQLi doesn#39;t recognize login info(PHP MySQLi 無法識別登錄信息)
                  mysqli_select_db() expects exactly 2 parameters(mysqli_select_db() 需要 2 個參數)
                  Php mysql pdo query: fill up variable with query result(Php mysql pdo 查詢:用查詢結果填充變量)
                  MySQLI 28000/1045 Access denied for user #39;root#39;@#39;localhost#39;(MySQLI 28000/1045 用戶“root@“localhost的訪問被拒絕)
                  <legend id='o2ELl'><style id='o2ELl'><dir id='o2ELl'><q id='o2ELl'></q></dir></style></legend>
                    • <bdo id='o2ELl'></bdo><ul id='o2ELl'></ul>

                          <small id='o2ELl'></small><noframes id='o2ELl'>

                          <i id='o2ELl'><tr id='o2ELl'><dt id='o2ELl'><q id='o2ELl'><span id='o2ELl'><b id='o2ELl'><form id='o2ELl'><ins id='o2ELl'></ins><ul id='o2ELl'></ul><sub id='o2ELl'></sub></form><legend id='o2ELl'></legend><bdo id='o2ELl'><pre id='o2ELl'><center id='o2ELl'></center></pre></bdo></b><th id='o2ELl'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='o2ELl'><tfoot id='o2ELl'></tfoot><dl id='o2ELl'><fieldset id='o2ELl'></fieldset></dl></div>

                            <tfoot id='o2ELl'></tfoot>

                              <tbody id='o2ELl'></tbody>
                            主站蜘蛛池模板: 欧美日韩黄色一级片 | 免费一区二区 | 99综合在线 | 国产区在线观看 | 黄色一级毛片 | 91精品福利| 不卡在线视频 | 日韩精品一区二区三区高清免费 | 精品欧美一区二区三区免费观看 | 亚洲瑟瑟 | 国产精品3区 | 不卡在线视频 | 亚洲国产精品久久人人爱 | 国产伦一区二区三区四区 | 激情毛片 | 久久首页 | 精品久久中文字幕 | 九九热最新视频 | 日本天堂视频在线观看 | 国产精品亚洲一区二区三区在线 | 91在线观看 | 激情综合五月天 | 色资源在线 | www.日本国产| 日本91av视频 | 日韩欧美在线观看视频 | 超碰国产在线 | 91亚洲精选 | 国产在线一区二区 | 99精品欧美一区二区三区综合在线 | 狠狠躁18三区二区一区 | 污污的网站在线观看 | 97精品一区二区 | 成人久久18免费 | 欧美二区三区 | 日本免费一区二区三区视频 | a久久| 亚洲一区二区视频 | 日本在线看片 | 韩国av一区二区 | 黄色一级免费观看 |