PHP ODBC - How To Get the Number of Affected Rows?
Submitted by: AdministratorIf 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('ggl_SQL_SERVER','sa','GlobalGuideLine');
$sql = "INSERT INTO ggl_links"
. " SELECT id+1000, REVERSE(url), notes, counts, time"
. " FROM ggl_links WHERE id > 1000";
$res = odbc_exec($con, $sql);
if (!$res) {
print("SQL statement failed with error: ");
print(odbc_error($con).": ".odbc_errormsg($con)." ");
} else {
$number_of_rows = odbc_num_rows($res);
print("$number_of_rows rows inserted. ");
}
odbc_close($con);
If you run this script, you should get:
2 rows inserted
Submitted by: Administrator
The following tutorial script shows you report back the number of rows inserted properly:
<?php
$con = odbc_connect('ggl_SQL_SERVER','sa','GlobalGuideLine');
$sql = "INSERT INTO ggl_links"
. " SELECT id+1000, REVERSE(url), notes, counts, time"
. " FROM ggl_links WHERE id > 1000";
$res = odbc_exec($con, $sql);
if (!$res) {
print("SQL statement failed with error: ");
print(odbc_error($con).": ".odbc_errormsg($con)." ");
} else {
$number_of_rows = odbc_num_rows($res);
print("$number_of_rows rows inserted. ");
}
odbc_close($con);
If you run this script, you should get:
2 rows inserted
Submitted by: Administrator
Read Online MS SQL Server Job Interview Questions And Answers
Top MS SQL Server Questions
☺ | What Happens If You Insert a Duplicate Key for the Primary Key Column in MS SQL Server? |
☺ | What Are the Character String Functions Supported by SQL Server 2005? |
☺ | How To Execute the Cursor Queries with "OPEN" Statements? |
☺ | PHP MSSQL - How To Display a Past Time in Days, Hours and Minutes? |
☺ | How To Configure ODBC DSN with Different Port Numbers? |
Top Databases Programming Categories
☺ | RDBMS Interview Questions. |
☺ | SQL Interview Questions. |
☺ | SSRS Interview Questions. |
☺ | Sybase Interview Questions. |
☺ | Database Administrator (DBA) Interview Questions. |