cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

possible bug in sa16 PHP sasql_affected_rows?

3,516

I'm getting different results from sasql_affected_rows() with sasql_query() vs sasql_stmt_execute() and I can't see what I'm doing wrong. (I use sasql_stmt_execute() because I use prepared statements.)

After sasql_query, I get the proper number of rows, while after sasql_stmt_execute, the affected rows are always zero. Here's my test code:

    $cstring = "DSN=demo16;UID=DBA;PWD=sql";
    $sql = "UPDATE Customers SET ID = ID;";

//test 1
$conn = sasql_connect( $cstring );
sasql_set_option( $conn, "auto_commit", "off" );
print "sasql_query() $sql\\n";
$rs = sasql_query( $conn, $sql );
print "sasql_affected_rows()=".sasql_affected_rows($conn)."\\n";
sasql_close( $conn );

//test 2
$conn = sasql_connect( $cstring );
sasql_set_option( $conn, "auto_commit", "off" );
print "sasql_stmt_execute() $sql\\n";
$pstmt = sasql_prepare( $conn, $sql );
sasql_stmt_execute( $pstmt );   
print "sasql_affected_rows()=".sasql_affected_rows($conn)."\\n";
sasql_close( $conn );


and the output is:

sasql_query() UPDATE Customers SET ID = ID;
sasql_affected_rows()=126
sasql_stmt_execute() UPDATE Customers SET ID = ID;
sasql_affected_rows()=0

Has anyone else seen this?

View Entire Topic
Former Member

The function you need to use for the sasql_stmt_execute() case is a different one

 int sasql_stmt_affected_rows( sasql_stmt $stmt )


http://dcx.sybase.com/index.html#sa160/en/dbprogramming/php-stmt-affected-rows.html

Calling sasql_affected_rows() is picking up the result set from the connection object and thus the last query.

Hopefully this will make this a little clearer.

0 Kudos

Nick, thanks a lot for looking into this - big help! I should have been able to see that 😞