Jump to content

php with ms sql


patchido
Go to solution Solved by 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);
    ?>


Edited by patchido
Link to comment
Share on other sites

  • Solution

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.