首页 > 解决方案 > sqlsrv_fetch_object 返回字符串数据,右截断

问题描述

我正在使用选择查询PHPMSSQL数据库中获取数据。但是当我使用时,sqlsrv_fetch_object我得到了错误:String data, right truncation。它只是从视图中选择查询,为什么我会收到此消息?

这是我的代码:

$connectionInfo = array( "UID"=>$uid,                            
                             "PWD"=>$pwd,                            
                             "Database"=>$databaseName); 

    /* Connect using SQL Server Authentication. */  
    $conn = sqlsrv_connect( $serverName, $connectionInfo);  

    $tsql = "SELECT custCode, custName, comments, incharge, currency, country, sellerID, sellerName, paymentMethod, category, dispatchMethod FROM [DataBase-Name].[dbo].[eshopCustomers]";

    $stmt = sqlsrv_query($conn, $tsql,[],[ "Scrollable" => SQLSRV_CURSOR_KEYSET ]);
    if( $stmt === false) {
        die( print_r( sqlsrv_errors(), true) );
    }
    //number of results
    $num = sqlsrv_num_rows($stmt);
    //if user is not in latest update then make him inactive
    $current_user_ids = [];
    if( $num > 0 ){
        for($i = 0; $i < $num; $i++){
            $cst = sqlsrv_fetch_object($stmt); print_r($cst);
            if( $cst === false ) {
                die( print_r( sqlsrv_errors(), true));
            } die();
...............................................................

标签: phpsql-server

解决方案


推荐阅读