Collections:
PHP MSSQL - mssql_rows_affected() - Number of Affected Rows
PHP MSSQL - How To Get the Number of Affected Rows?
✍: Guest
If you insert multiple rows with a single INSERT statement, you can use the mssql_rows_affected() function to find out how many rows were inserted. mssql_rows_affected($connection) returns the number of affected rows of the last INSET, UPDATE or DELETE statement.
The following tutorial script shows you report back the number of rows inserted properly:
<?php
$con = mssql_connect('LOCALHOST','sa','FYIcenter');
mssql_select_db('FyiCenterData', $con);
$sql = "INSERT INTO fyi_links"
. " SELECT id+1000, REVERSE(url), notes, counts, time"
. " FROM fyi_links WHERE id > 1000";
$res = mssql_query($sql,$con);
if (!$res) {
print("SQL statement failed with error:\n");
print(" ".mssql_get_last_message()."\n");
} else {
$number_of_rows = mssql_rows_affected($con);
print("$number_of_rows rows inserted.\n");
}
mssql_close($con);
If you run this script, you should get:
2 rows inserted
⇒ PHP MSSQL - Returning Result Set Objects
⇐ PHP MSSQL - Inserting Multiple Rows with a Subquery
⇑ SQL Server FAQs - PHP MSSQL Functions - Managing Tables and Data Rows
2024-02-28, 2255🔥, 0💬
Popular Posts:
Can You Drop an Index Associated with a Unique or Primary Key Constraint in Oracle? You can not dele...
How To Convert Binary Strings into Integers in SQL Server Transact-SQL? Binary strings and integers ...
How To Use DATEADD() Function in SQL Server Transact-SQL? DATEADD() is a very useful function for ma...
Can Date and Time Values Be Converted into Integers in SQL Server Transact-SQL? Can date and time va...
How To Use "IF ... ELSE IF ..." Statement Structures in SQL Server Transact-SQL? "IF ... ELSE IF ......