Switch to: V11V10V9V8V7V6V5

valentina_affected_rows()

Declaration

int valentina_affected_rows ( [resource link_identifier] )       

Parameters

Name Description
link_identifier The Valentina Server connection. If the link identifier is not specified, the last link opened by valentina_connect() is assumed. If by chance no connection is found, an E_WARNING level warning is generated.

Description

Gets the number of affected rows in previous Valentina Server operation.

Return Values

Returns the number of affected rows on success, and -1 if the last query failed.

When using UPDATE, VServer will not update columns where the new value is the same as the old value. This creates the possibility that valentina_affected_rows() may not actually equal the number of rows matched, only the number of rows that were literally affected by the query.

Examples

Example 1.

<?php
$link = valentina_connect('localhost', 'val_user', 'val_password');
if (!$link) {
   die('Could not connect: ' . valentina_error());
}
valentina_select_db('db_test');
 
/* this should return the correct numbers of deleted records */
valentina_query('DELETE FROM mytable WHERE id < 10');
printf("Records deleted: %d\n", valentina_affected_rows());
 
/* with a where clause that is never true, it should return 0 */
valentina_query('DELETE FROM mytable WHERE 0');
printf("Records deleted: %d\n", valentina_affected_rows());
?> 

The above example will output something similar to:

Records deleted: 10
Records deleted: 0

Example 2.

<?php
$link = valentina_connect('localhost', 'val_user', 'val_password');
if (!$link) {
   die('Could not connect: ' . valentina_error());
}
valentina_select_db('db_test');
 
/* Update records */
valentina_query("UPDATE mytable SET used=1 WHERE id < 10");
printf ("Updated records: %d\n", valentina_affected_rows());
?> 

The above example will output something similar to:

Update Records: 10

Notes

SELECT Statements: To retrieve the number of rows returned by a SELECT, it is possible to use: valentina_num_rows().

See Also