Collections:
PHP ODBC - odbc_num_rows() - Number of Affected Rows
PHP ODBC - How To Get the Number of Affected Rows?
✍: Guest
If you insert multiple rows with a single INSERT statement, you can use the odbc_num_rows() function to find out how many rows were inserted. odbc_num_rows($result_set) returns the number of affected rows based on the result set object returned by the last INSET, UPDATE or DELETE statement.
The following tutorial script shows you report back the number of rows inserted properly:
<?php
$con = odbc_connect('FYI_SQL_SERVER','sa','FYIcenter');
$sql = "INSERT INTO fyi_links"
. " SELECT id+1000, REVERSE(url), notes, counts, time"
. " FROM fyi_links WHERE id > 1000";
$res = odbc_exec($con, $sql);
if (!$res) {
print("SQL statement failed with error:\n");
print(odbc_error($con).": ".odbc_errormsg($con)."\n");
} else {
$number_of_rows = odbc_num_rows($res);
print("$number_of_rows rows inserted.\n");
}
odbc_close($con);
If you run this script, you should get:
2 rows inserted
⇒ PHP ODBC - Returning Result Set Objects
⇐ PHP ODBC - Inserting Multiple Rows with a Subquery
⇑ SQL Server FAQs - PHP ODBC Functions - Managing Tables and Data Rows
2024-05-29, 2166🔥, 0💬
Popular Posts:
What Are Bitwise Operations in SQL Server Transact-SQL? Bitwise operations are binary operations per...
How To Use GO Command in "sqlcmd" in SQL Server? "sqlcmd" is a command line client application to ru...
How To Convert Character Strings into Numeric Values in SQL Server Transact-SQL? Sometimes you need ...
How to change the data type of an existing column with "ALTER TABLE" statements in SQL Server? Somet...
How To Locate and Take Substrings with CHARINDEX() and SUBSTRING() Functions in SQL Server Transact-...