Viewed   596 times

I am trying to get the number of rows returned in a query. The while loop looping through the results works, but for some reason the sqlsrv_num_rows does not return any value:

$result = "SELECT * from dtable WHERE id2 = 'apple'";
$query = sqlsrv_query($conn, $result);

$row_count = sqlsrv_num_rows($query);
echo $row_count;

while($row = sqlsrv_fetch_array($query))
      echo 'yes';




It is because sqlsrv_query() uses SQLSRV_CURSOR_FORWARD cursor type by default. However, in order to get a result from sqlsrv_num_rows(), you should choose one of these cursor types below:


For more information, check: Cursor Types (SQLSRV Driver)

In conclusion, if you use your query like:

$query = sqlsrv_query($conn, $result, array(), array( "Scrollable" => 'static' ));

you will get result in:

$row_count = sqlsrv_num_rows($query);
Sunday, December 11, 2022

First if I'm not wrong you are storing sqlsrv_connect result into $conn and this result isn't a class obj its a resource, so remove $db->conn

This example, will connect, then fetch if there are resources returned from sqlsrv_query

$conn_array = array (
    "UID" => "sa",
    "PWD" => "root",
    "Database" => "nih_bw",
$conn = sqlsrv_connect('BILAL', $conn_array);
if ($conn){
    echo "connected";
    if(($result = sqlsrv_query($conn,"SELECT * FROM routines")) !== false){
        while( $obj = sqlsrv_fetch_object( $result )) {
              echo $obj->colName.'<br />';
    die(print_r(sqlsrv_errors(), true));
Friday, November 18, 2022

There's an unofficial driver. Not sure if that will pass PCI.

Sunday, September 25, 2022

In this line:


You are discarding the return value, you need to assign it to a variable:

sales1 = getSales(division);
Saturday, November 5, 2022

Hi I raised this issue to facebook developer support and the issue is that I have not implemented the correct delegate methods for iOS10. and you can find the correct delegate implementation here

import UIKit
import CoreData

class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

public func application(_ application: UIApplication,  didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
// Override point for customization after application launch.

return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)

 public func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {

return FBSDKApplicationDelegate.sharedInstance().application(
  open: url as URL!,
  sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as! String,
  annotation: options[UIApplicationOpenURLOptionsKey.annotation]

public func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(
  open: url as URL!,
  sourceApplication: sourceApplication,
  annotation: annotation)
Friday, December 23, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :