patchido Posted February 26, 2014 Share Posted February 26, 2014 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); ?> Link to comment https://forums.phpfreaks.com/topic/286560-php-with-ms-sql/ 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' Link to comment https://forums.phpfreaks.com/topic/286560-php-with-ms-sql/#findComment-1470840 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 Link to comment https://forums.phpfreaks.com/topic/286560-php-with-ms-sql/#findComment-1470841 Share on other sites More sharing options...
patchido Posted February 27, 2014 Author 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. Link to comment https://forums.phpfreaks.com/topic/286560-php-with-ms-sql/#findComment-1470858 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.