patchido Posted February 26, 2014 Share Posted February 26, 2014 (edited) so i am trying to connect to my sql through php. i am getting a connection, if i copy that query and place it over sql management studio i do get the results needed. what am i missing? I just get this on the response. Connection createdRows returned: <?php $serverName = "************"; $databaseName = "*********"; $connectionInfo = array("Database"=>"$databaseName", "UID"=>"*******","PWD"=>"*********"); $conn = sqlsrv_connect( $serverName, $connectionInfo); if( $conn === false ){ echo "Could not connect.\n"; die( print_r( sqlsrv_errors(), true)); } else{ echo "Connection created"; } $tsql = "SELECT TOP 10 * FROM dbo.ActivityLog"; $result = sqlsrv_query($conn, $tsql); echo "Rows returned: ". sqlsrv_num_rows($result); sqlsrv_close($conn); ?> Edited February 26, 2014 by patchido Quote Link to comment Share on other sites More sharing options...
tunage Posted February 27, 2014 Share Posted February 27, 2014 the server address for starters. i.e. host='localhost' Quote Link to comment Share on other sites More sharing options...
patchido Posted February 27, 2014 Author Share Posted February 27, 2014 Does asteriscs are for me not to reveal my info, the connection is successful, i get the right response but no rows Quote Link to comment Share on other sites More sharing options...
Solution patchido Posted February 27, 2014 Author Solution Share Posted February 27, 2014 solved, the function sqlsrv_num_rows need this $params = array(); $options = array( "Scrollable" => SQLSRV_CURSOR_KEYSET ); $result = sqlsrv_query($conn, $tsql,$params,$options); from php.net Retrieves the number of rows in a result set. This function requires that the statment resource be created with a static or keyset cursor. For more information, see sqlsrv_query(), sqlsrv_prepare(), or » Specifying a Cursor Type and Selecting Rowsin the Microsoft SQLSRV documentation. Quote Link to comment 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.