MSSQL returning wrong result
Posted: March 20th, 2015, 11:40 pm
I discovered something weird with the managed MSSQL extension.
When I use mssql_connect('host,1344', 'user', 'pass') providing a port number, after some queries, mssql_fetch_assoc() returns a wrong result = array("computed" => 1) instead if a valid result.
When I connect using mssql_connect('host', 'user', 'pass') without the port, it always works as expected.
I will now provide more details in order to guess what could be the reason for this weird behaviour:
1) For this code...
...the result fails each 3 times (always) returning array('computed' => 1) for any $sql.
2) For this code...
...the result fails each 3 times (always) returning NULL for any $sql.
3) For this code...
...it "never" fails (I tried about 20 times).
4) For this code...
...the result fails each 3 times (always) returning array('computed' => 1) for any $sql.
5) For this code...
...it "never" fails (I tried about 20 times).
6) If I repeat the query (in the same request / connection) many times...
...it only fails each 3 requests for the first query, but not the other ones.
Remarks:
It seems like it is related with the fact that I'm providing a port number ("host,port") and using mssql_select_db('dbname').
I'm running this code on Mono (Mono JIT compiler version 2.11.4) on CentOS Linux.
I don't have problems accessing the SQL Server with "host" or "host,port" from MS Visual Studio's Database Explorer.
Any idea what could be the problem?
When I use mssql_connect('host,1344', 'user', 'pass') providing a port number, after some queries, mssql_fetch_assoc() returns a wrong result = array("computed" => 1) instead if a valid result.
When I connect using mssql_connect('host', 'user', 'pass') without the port, it always works as expected.
I will now provide more details in order to guess what could be the reason for this weird behaviour:
1) For this code...
- Code: Select all
mssql_pconnect($host . ',' . $port, $user, $pass);
mssql_select_db($db);
mssql_query("SET DATEFORMAT ymd");
$cur = mssql_query("SELECT 'ok' AS test");
$res = mssql_fetch_assoc($cur);
...the result fails each 3 times (always) returning array('computed' => 1) for any $sql.
2) For this code...
- Code: Select all
mssql_pconnect($host . ',' . $port, $user, $pass);
mssql_select_db($db);
// mssql_query("SET DATEFORMAT ymd");
$cur = mssql_query("SELECT 'ok' AS test");
$res = mssql_fetch_assoc($cur);
...the result fails each 3 times (always) returning NULL for any $sql.
3) For this code...
- Code: Select all
mssql_pconnect($host . ',' . $port, $user, $pass);
// mssql_select_db($db);
// mssql_query("SET DATEFORMAT ymd");
$cur = mssql_query("SELECT 'ok' AS test");
$res = mssql_fetch_assoc($cur);
...it "never" fails (I tried about 20 times).
4) For this code...
- Code: Select all
mssql_pconnect($host . ',' . $port, $user, $pass);
// mssql_select_db($db);
mssql_query("SET DATEFORMAT ymd");
$cur = mssql_query("SELECT 'ok' AS test");
$res = mssql_fetch_assoc($cur);
...the result fails each 3 times (always) returning array('computed' => 1) for any $sql.
5) For this code...
- Code: Select all
mssql_pconnect($host, $user, $pass);
mssql_select_db($db);
mssql_query("SET DATEFORMAT ymd");
$cur = mssql_query("SELECT 'ok' AS test");
$res = mssql_fetch_assoc($cur);
...it "never" fails (I tried about 20 times).
6) If I repeat the query (in the same request / connection) many times...
- Code: Select all
mssql_pconnect($host . ',' . $port, $user, $pass);
mssql_select_db($db);
mssql_query("SET DATEFORMAT ymd");
// Result will only fail here each 3 requests
$cur = mssql_query("SELECT 'ok' AS test");
$res = mssql_fetch_assoc($cur);
// It "never" fails here
$cur = mssql_query("SELECT 'ok' AS test");
$res = mssql_fetch_assoc($cur);
// Nor here
$cur = mssql_query("SELECT 'ok' AS test");
$res = mssql_fetch_assoc($cur);
...
...it only fails each 3 requests for the first query, but not the other ones.
Remarks:
It seems like it is related with the fact that I'm providing a port number ("host,port") and using mssql_select_db('dbname').
I'm running this code on Mono (Mono JIT compiler version 2.11.4) on CentOS Linux.
I don't have problems accessing the SQL Server with "host" or "host,port" from MS Visual Studio's Database Explorer.
Any idea what could be the problem?