Answers

Question and Answer:

  Home  MS SQL Server

⟩ PHP ODBC - How To Get the Number of Affected Rows?

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('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

 127 views

More Questions for you: