Welcome Guest, Not a member yet? Register   Sign In
Issue with sqlserver drivers not returning rows
#1

Hi everyone.

This morning I've encountered a strange issue in CI3. I have a pretty standard user profile page that doesn't do anything particularly complicated.

I connect successfully to a SQLServer DB (and have done for years) and the code I use to return the data is as follows
Code:
public function getMemberDetails($identifier)
    $query = "EXEC [spr_GetMemberDetails] @pIdentifier = '{$identifier}', @pIdentifierType = 'C';";
    return $this->thedb->query($query)->result();
}


Three generated queries would be
EXEC [spr_GetMemberDetails] @pIdentifier = '5499976581715', @pIdentifierType = 'C';
EXEC [spr_GetMemberDetails] @pIdentifier = '5499976577317', @pIdentifierType = 'C';
EXEC [spr_GetMemberDetails] @pIdentifier = '5499976308597', @pIdentifierType = 'C';

When I execute the queries natively in SQL Management studio (with the same DB details on the same DB) I get results returned for each query with no issues, and no other messages. Just the expected record. The stored procedure only has one output regardless. 

However if I run the getMemberDetails (with those ID's above) , e.g. 
Code:
$member = $this->thedb->getMemberDetails(5499976581715);


I only get results for one of the queries (@pIdentifier = 5499976308597).

This struck me as very strange so I tested again using basic code (again, same server, user and password)..


Code:
public function test($identifier){
    $serverName = "******;
    $connectionInfo = array( "Database"=>"******", "UID"=>"******", "PWD"=>'******');
   
    $conn = sqlsrv_connect( $serverName, $connectionInfo );
    if( $conn === false ) {
        die( print_r( sqlsrv_errors(), true));
    }

    $sql = "EXEC [spr_GetMemberDetails] @pIdentifier = '{$identifier}', @pIdentifierType = 'C';";
    $stmt = sqlsrv_query( $conn, $sql );
    if( $stmt === false) {
        die( print_r( sqlsrv_errors(), true) );
    }

    while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) {
        print_r($row);
    }

    sqlsrv_free_stmt( $stmt);
}


which DOES return data, in every case. 

So - on SSMS the queries work
using vanilla PHP works, e.g. 

Code:
$this->thedb->test(5499976581715); //OK
$this->thedb->test(5499976577317); //OK
$this->thedb->test(5499976308597); //OK

but using CI, it doesn't work.

Code:
$this->thedb->getMemberDetails(5499976581715); //NOT OK
$this->thedb->getMemberDetails(5499976577317); //NOT OK
$this->thedb->getMemberDetails(5499976308597); //OK

The problem has to be related to the identifiers as the latter one always works, no matter what order I use.

I've checked the source data and I can honestly see nothing wrong whatsoever. I've attached the data (with personal info removed). Copying the data to other test rows work file, so it doesn't appear to be the data at fault either.

Anyway - has anyone seen this kind of behavior before? Is there something weird in the sqlserver drivers that break sometimes? I've gone through them and they look pretty clean.

Thanks for any help you might have

All the best
Reply




Theme © iAndrew 2016 - Forum software by © MyBB