Flourish PHP Unframework
This is an archived copy of the forum for reference purposes

Prepared Statement - affected rows

posted by darren 8 years ago

Hi,


$statement = $db->prepare("INSERT INTO ender (report_group_id, pm_total) VALUES (%i, %i)");

foreach ($data as $id => $total)
{
	$db->query($statement, $id, $total);
}

Hows can you use countAffectedRows() on a prepared statement?

Thanks,

Darren

An fResult object is returned from fDatabase::query(), even if an fStatement object is used in place of the SQL.

$statement = $db->prepare("INSERT INTO ender (report_group_id, pm_total) VALUES (%i, %i)");
foreach ($data as $id => $total)
{
    $result = $db->query($statement, $id, $total);
    echo $result->countAffectedRows();
}
posted by wbond 8 years ago

I was thinking to reply with a similar answer but I since it was one query foreach key in $data, the only thing I can think to do is to keep a count going in the loop and to keep calling countAffectedRows(). What I thought is that they're might be a better solution, such as counting affected rows after the transaction before committing.

posted by audvare 8 years ago

Also, if your prepared statement is an insert statement, then each time it is executed, one row will be affected, or an fSQLException will be thrown.

posted by wbond 8 years ago