|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2005-09-16 11:30 UTC] matthew_peters at uk dot ibm dot com
Description:
------------
I find the following piece of code gives different results depending on whether I use the MySQL driver (I get value 1) or the ODBC driver (I get value 0). In both cases the INSERT has actually succeeded. Am I doing something wrong?
FWIW the levels I am using are a 5.1.0RC2 20050916 version of PHP (I am wedded to this version but presumably that is good since it will contain the most recent version of PDO) but PDO drivers taken from a RC1 build (I can't find any relevant PDO drivers in the RC2 build output on snaps - only a firebird one, and didn't succeed when I tried to build them myself as part of the PHP build).
Incidentally if I use a literal SQL statement and $rows->$dbh->exec('INSERT...'); then the rows number comes out right both times.
Reproduce code:
---------------
$stmt = 'INSERT INTO company (name) VALUES(?)';
$pdo_stmt = $dbh->prepare($stmt);
$value_list = array('Acme');
$pdo_stmt->execute($value_list);
$rows_affected = $pdo_stmt->rowCount();
echo "rows = $rows_affected\n";
Expected result:
----------------
I want to see a value of 1 for the row I have just inserted.
Actual result:
--------------
0 when $dbh is pointed at db2 with odbc, 1 when $dbh is pointed at mysql.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 07 01:00:01 2025 UTC |
When I compare the respective statement executors for mysql and odbc: (i.e. files ...\pdo_odbc\odbc_stmt.c and ...\pdo_mysql\mysql_statement.c) I find that routine pdo_mysql_stmt_execute picks up the row count after executing the query: row_count = mysql_stmt_affected_rows(S->stmt); after executing the query whereas routine odbc_statement_execute does not. I don't know if this is the right fix but if in odbc_statement_execute I add a declare: long row_count = -1; and down the bottom, after the switch on the rc from the execute the two lines: rc = SQLRowCount(S->stmt, &row_count); stmt->row_count = row_count; then the row count is set correctly.