Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : Microsoft SQL Server Functions : mssql_rows_affected

mssql_rows_affected

Returns the number of records affected by the query (PHP 4 >= 4.0.4, PHP 5, PECL odbtp:1.1.1-1.1.4)
int mssql_rows_affected ( resource link_identifier )

Examples ( Source code ) » mssql_rows_affected

<?php
// Delete all rows in a table
mssql_query('TRUNCATE TABLE [php].[dbo].[persons]');

echo 
'Deleted ' mssql_affected_rows($link) . ' row(s)';
?>

Examples 2

<?php
$link 
mssql_pconnect($db_host,$db_user,$db_pass);
mssql_select_db($db_name$link);

$result mssql_query('Select 1'$link);

$rows mssql_rows_affected($result); # ERROR!
$rows mssql_rows_affected($link); # Correct
?>

Code Examples / Notes » mssql_rows_affected

rowan dot collins

Note that, as the page says, this function expects an MSSQL *Link* resource, not a *result* resource. This is a bit counter-intuitive, and differs from, for instance, pg_affected_rows (though not, apparently, mysql_affected_rows).
<?php
$link = mssql_pconnect($db_host,$db_user,$db_pass);
mssql_select_db($db_name, $link);
$result = mssql_query('Select 1', $link);
$rows = mssql_rows_affected($result); # ERROR!
$rows = mssql_rows_affected($link); # Correct
?>


pierre gros

i don't know why, but on my linux debian with php5 I get a nice :
Fatal error: Call to undefined function mssql_rows_affected()
when I try to use this function.
So if you have some problems, try to use this :
1st function (the one with mssql_rows_affected):
<?php
function update($query){
mssql_query($query,$ressource);
return mssql_rows_affected($ressource);
}
?>
new function (the one I use now) :
<?php
function update($query){
mssql_query($query,$ressource);
$rsRows = mssql_query("select @@rowcount as rows", $ressource);
$rows = mssql_fetch_assoc($rsRows);
return $rows['rows'];
}
?>


Change Language


Follow Navioo On Twitter
mssql_bind
mssql_close
mssql_connect
mssql_data_seek
mssql_execute
mssql_fetch_array
mssql_fetch_assoc
mssql_fetch_batch
mssql_fetch_field
mssql_fetch_object
mssql_fetch_row
mssql_field_length
mssql_field_name
mssql_field_seek
mssql_field_type
mssql_free_result
mssql_free_statement
mssql_get_last_message
mssql_guid_string
mssql_init
mssql_min_error_severity
mssql_min_message_severity
mssql_next_result
mssql_num_fields
mssql_num_rows
mssql_pconnect
mssql_query
mssql_result
mssql_rows_affected
mssql_select_db
eXTReMe Tracker