PHP Australia Conference 2015

sybase_affected_rows

(PHP 4, PHP 5)

sybase_affected_rowsGets number of affected rows in last query

Beschreibung

int sybase_affected_rows ([ resource $link_identifier ] )

sybase_affected_rows() returns the number of rows affected by the last INSERT, UPDATE or DELETE query on the server associated with the specified link identifier.

This command is not effective for SELECT statements, only on statements which modify records. To retrieve the number of rows returned from a SELECT, use sybase_num_rows().

Parameter-Liste

link_identifier

If the link identifier isn't specified, the last opened link is assumed.

R├╝ckgabewerte

Returns the number of affected rows, as an integer.

Beispiele

Beispiel #1 Delete-Query

<?php
/* connect to database */
sybase_connect('SYBASE''''') or
die(
"Could not connect");
sybase_select_db("db");

sybase_query("DELETE FROM sometable WHERE id < 10");
printf("Records deleted: %d\n"sybase_affected_rows());
?>

Das oben gezeigte Beispiel erzeugt folgende Ausgabe:

Records deleted: 10

Siehe auch

add a note add a note

User Contributed Notes 2 notes

up
0
james at lasolas dot com
14 years ago
If you get a segfault with sybase-ct, add a en_US entry to your $SYBASE/locales/locales.dat file:

[linux]
    locale = en_US, us_english, iso_1
    ...
up
-1
neugeypc at cox dot net
12 years ago
The sybase_affected_rows() function seems to work now with the Sybase DB Library.  Not sure when this improvement was made, but I'm currently running PHP 4.1.2 on Solaris.

Affected rows seems to return a -1 if the query syntax was incorrect on the last submitted query.
Affected rows returns 0 if no rows were affected or another error occured, such as a foreign key violation and also returns 0 if the query was successfully, but no records were affected by the query.
If the query was valid and did affect some rows, sybase_affected_rows() seems to be returning the correct number.
To Top