PDOStatement::rowCount
SQL Server 2008 R2
Returns the number of rows added, deleted, or changed by the last statement.
This example shows two uses of rowCount. The first use returns the number of rows that were added to the table. The second use shows that rowCount can return the number of rows in a result set when you specify a scrollable cursor.
<?php $database = "Test"; $server = "(local)"; $conn = new PDO( "sqlsrv:server=$server ; Database = $database", "", ""); $col1 = 'a'; $col2 = 'b'; $query = "insert into Table2(col1, col2) values(?, ?)"; $stmt = $conn->prepare( $query ); $stmt->execute( array( $col1, $col2 ) ); print $stmt->rowCount(); echo "\n\n"; $con = null; $database = "AdventureWorks"; $conn = new PDO( "sqlsrv:server=$server ; Database = $database", "", ""); $query = "select * from Person.ContactType"; $stmt = $conn->prepare( $query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL)); $stmt->execute(); print $stmt->rowCount(); ?>
