Reputation: 43
I have a PHP application which needs to query a Microsoft SQL database. That's easy enough, but I'm having trouble getting a "num_rows" from the result set ($rs)...here's my code, and some things I have tried - any help appreciated!
$conn = new COM ("ADODB.Connection")or die("Cannot start ADO"); $connStr = "PROVIDER=SQLOLEDB;SERVER=SQLServerIP;UID=UserID;PWD=MyPassword;DATABASE=MyDatabase"; $conn->open($connStr); $rs = $conn->execute($q); //Tried this: - gives error $num = $rs->field_count; //And this: - gives error $num = $rs->num_rows; //Any Ideas out there?
I know $rs holds the data, because I can successfully pull the data out with:
echo $rs->Fields('Column1'); echo $rs->Fields('Column2');
Upvotes: 1
Views: 279
Reputation: 493
If that is the full snippet of your code, it looks like you are missing your actual SQL query.
See the line: $rs = $conn->execute($q);
Presumably, $q
should be your sql query you are executing
So above your $rs, are we just missing some $q = SELECT * FROM foo;
?
Upvotes: 0
Reputation: 49
try this I think it may help you
int mssql_num_rows ( resource $result )
mssql_num_rows() // returns the number of rows in a result set.
and here is the documentation's link for any extra info you need enter link description here
Upvotes: 0
Reputation: 3624
You're not using the right API. Try $rs->Fields->Count()
. Refer to http://php.net/manual/en/class.com.php as you are using the Com
class to access the database.
Upvotes: 0