kris1988edwards Posted December 17, 2014 Share Posted December 17, 2014 Hello, I am trying to run a report as per the below mssql query: $query = "SELECT tblWJCItem.AddedDescription, tblWJC.WJCPrefix, tblWJC.WJCNo, tblWJCItem.MaterialName, tblStockFamily.StockFamily, tblWJCItem.WeightToSend, tblWJC.DateCreated, tblWJC.WJCStatusID FROM tblWJC INNER JOIN tblCustomer ON tblWJC.CustomerID = tblCustomer.CustomerID INNER JOIN tblWJCStockStatus ON tblWJC.WJCStockStatusID = tblWJCStockStatus.WJCStockStatusID INNER JOIN tblStockStatus ON tblWJC.WJCID = tblStockStatus.WJCID LEFT OUTER JOIN tblWJCProductLine ON tblWJC.WJCID = tblWJCProductLine.WJCID LEFT OUTER JOIN tblWJCStockItem ON tblWJCProductLine.WJCProductLineID = tblWJCStockItem.tblWJCStockItem INNER JOIN tblStockFamily ON tblWJCItem.ProductFamilyID = tblStockFamily.StockFamilyID WHERE tblCustomer.CustomerName = 'NAME' AND tblWJCStockStatus.WJCStockStatus <> 'Stock Usage Confirmed' ORDER BY tblWJC.WJCID"; and then fetch the results by the following php code: $result = sqlsrv_query($conn, $query); while($row = sqlsrv_fetch_object($result)){ echo $row->AddedDescription .",".$row->WJCPrefix .",".$row->WJCNo.",".$row->MaterialName.",".$row->StockFamily.",".$row->WeightToSend.",".$row->DateCreated->format('d-m-Y').",".$row->WJCStatusID ."<br />"; } The connection to the database does get established but no results come through, i've got error reporting on in my php and the following message gets given: Warning: sqlsrv_fetch_object() expects parameter 1 to be resource, boolean given in C:\inetpub\wwwroot\kris\abs\test\rollsroyce.php on line 31 Line 31 is the while($row = sqlsrv_fetch_object($result)) Can anyone help with sorting this out its really starting to annoy me now. . Quote Link to comment https://forums.phpfreaks.com/topic/293145-mssql-and-php-query-issues/ Share on other sites More sharing options...
ginerjm Posted December 17, 2014 Share Posted December 17, 2014 (edited) That is why one should ALWAYS CHECK RESULTS of an operation. If you had you would have seen that False being returned by your query call. Basically your query is flawed. Edited December 17, 2014 by ginerjm Quote Link to comment https://forums.phpfreaks.com/topic/293145-mssql-and-php-query-issues/#findComment-1499851 Share on other sites More sharing options...
kris1988edwards Posted December 17, 2014 Author Share Posted December 17, 2014 That is why one should ALWAYS CHECK RESULTS of an operation. If you had you would have seen that False being returned by your query call. Basically your query is flawed. When I run the SQL directly on the server it runs and returns results fine its just when it goes into the php script Quote Link to comment https://forums.phpfreaks.com/topic/293145-mssql-and-php-query-issues/#findComment-1499852 Share on other sites More sharing options...
mac_gyver Posted December 17, 2014 Share Posted December 17, 2014 the php.net documentation for sqlsrv_query() contains an example of how to test for query errors and how to display the error information if there is an error. Quote Link to comment https://forums.phpfreaks.com/topic/293145-mssql-and-php-query-issues/#findComment-1499853 Share on other sites More sharing options...
mac_gyver Posted December 17, 2014 Share Posted December 17, 2014 i looked at your horrifically verbose query (you need to use better table names, column names, use aliases in the query and some white-space to format the query) and there's an obvious error in a column reference, so, i doubt the exact query you posted here, that's producing a query error, is the one that you ran directly against your database server. Quote Link to comment https://forums.phpfreaks.com/topic/293145-mssql-and-php-query-issues/#findComment-1499868 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.