I had the same problem as Pierre, but I think it could be a little bit better if the code was like the one above:
<?php
function update($sql){
$result = mssql_query($sql,$link);
if (function_exists('mssql_rows_affected')) {
return mssql_rows_affected($link);
} else {
$result = mssql_query("select @@rowcount as rows", $link);
$rows = mssql_fetch_assoc($result);
return $rows['rows'];
}
}
?>
mssql_rows_affected
(PHP 4 >= 4.0.4, PHP 5, PECL odbtp:1.1.1-1.1.4)
mssql_rows_affected — Restituisce il numero di record coinvolti dalla query
Descrizione
int mssql_rows_affected
( resource $id_connessione
)
Avviso
Questa funzione, al momento non è documentata; è disponibile soltanto la lista degli argomenti.
mssql_rows_affected
ricalb at globo dot com
14-Feb-2008 10:35
14-Feb-2008 10:35
Pierre Gros
31-Jul-2007 01:49
31-Jul-2007 01:49
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'];
}
?>
rowan dot collins at gmail dot com
31-May-2007 07:12
31-May-2007 07:12
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
?>
