Jump to content

php with ms sql


patchido

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.