Result Differ PHP 5.6 SQL Server 2014 and SQLSRV Driver Version 3.2

Category: sql server driverphp

Question

naknak987 on Tue, 07 Jun 2016 18:05:21


I've spent days on this with no luck. I've read this article several times through. SQL SRV Driver White Pages. Searching with Google yielded no results that worked. Any Insight would be appreciated. 

My setup, I am running XAMPP with Microsoft's SQLSRV 3.2 driver and  SQL Server 2014 developer edition on a Windows 7 machine.

If I make this query in Microsoft's Management Studio...

USE msdb
SELECT TABLE_NAME, TABLE_TYPE FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE='BASE TABLE'

I get 143 rows returned.

If I make the same query in PHP with this code...

<?php

$newConnectionInfo = array();
$newConnectionInfo['Database'] = "msdb";
$newConnectionInfo['UID'] = "";
$newConnectionInfo['PWD'] = "";
$newConnection = SQLSRV_CONNECT("127.0.0.1", $newConnectionInfo);
	
if ($newConnection){
	echo "<p>Connection Established.</p>";
	$params = array();
	$tsql = "SELECT TABLE_NAME, TABLE_TYPE FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE'";
	$options = array("scrollable" => SQLSRV_CURSOR_KEYSET);
	$getNames = SQLSRV_QUERY($newConnection, $tsql, $params, $options);
	if ($getNames){
		echo "<p>I got something here.</p>";
		var_dump($getNames);
		if (SQLSRV_HAS_ROWS($getNames)){
			$rowCount = SQLSRV_NUM_ROWS($getNames);
			var_dump($rowCount);
			while ($row = SQLSRV_FETCH_ARRAY($getNames, SQLSRV_FETCH_ASSOC)){
				echo "<p>There is more to be had!</p>";
				//var_dump($row);
			}
		}
	} else {
		echo "<p>Falure</p>";
		die (print_r(SQLSRV_ERRORS(), true));
	}
		
} else {
	echo "<p>Falure</p>";
	die(print_r(SQLSRV_ERRORS(), true));
}
	
?>

then I only get back 9 rows.

If you see what my mistake is please let me know.


Replies

Sam Zha on Wed, 08 Jun 2016 06:25:10


Hi naknak987,

Have you checked the permission? It seems that the account does only have public permission.

naknak987 on Wed, 08 Jun 2016 11:50:46


Hi naknak987,

Have you checked the permission? It seems that the account does only have public permission.


Sam Zha

I did not think that it would work because in management studio I was logging in with my Windows credentials and in PHP i was logging in with my Windows credentials. I would have thought that they would be the same. 

I created a new user in management studio with full permissions and now using that user account I am getting 143 rows like I should. Thank you for the help.