Output the number of rows affected from different queries:
<?php // Assume database username: root, password: 123456, database: CODERCTO $con = mysqli_connect ( "localhost" , "root" , "123456" , "CODERCTO" );if ( mysqli_connect_errno ( $con )){ echo "Failed to connect to MySQL: " . mysqli_connect_error ();} // Execute the query and output the number of affected rows mysqli_query ( $con , "SELECT * FROM websites" ); echo "The number of affected rows: " . mysqli_affected_rows ( $con ); echo "<br>" ; mysqli_query ( $con , "DELETE FROM websites WHERE alexa>1000" );echo "Number of rows affected: " . mysqli_affected_rows ( $con ); mysqli_close ( $con ); ?>The mysqli_affected_rows() function returns the number of record rows affected by the previous MySQL operation (SELECT, INSERT, UPDATE, REPLACE, DELETE).
mysqli_affected_rows( connection ) ;
parameter | describe |
---|---|
connection | Required. Specifies the MySQL connection to use. |
Return value: | An integer > 0 represents the number of rows affected. 0 means there are no affected records. -1 means the query returned an error. |
---|---|
PHP version: | 5+ |