ID: 27521 User updated by: getzeroedin at hotmail dot com Reported By: getzeroedin at hotmail dot com -Status: Feedback +Status: Closed Bug Type: ODBC related Operating System: Win2000 Prof PHP Version: 4.3.4 New Comment:
Yes. I've worked around it for now. I'll take it up with MySQL/MyODBC. Consider it closed. Previous Comments: ------------------------------------------------------------------------ [2004-03-08 06:44:43] [EMAIL PROTECTED] If same code works with Mssql, what makes you think it's bug in PHP but not in mysql/myodbc ? ------------------------------------------------------------------------ [2004-03-07 16:41:43] getzeroedin at hotmail dot com Description: ------------ When using PHP 4.3.4 and the Unified ODBC Functions (ODBC_PREPARE & ODBC_EXECUTE) to issue an "INSERT" SQL statement, the prepare is forcing the execution of an "INSERT" statement on the ODBC_PREPARE and on the ODBC_EXECUTE resulting in "Duplicate key error". The Insert statement being prepared uses placeholders (e.g. ?). Hence, the PREPARE statement inserts NULLS where those placeholders exist while the EXECUTE statement attempts to validly execute the INSERT statement, but an erroneous record already has been inserted during the PREPARE resulting in a "duplicate key error". I am using MySQL 4.0.18 and MyODBC 3.51.06. This worked fine on MS SQLServer but I want to use MySQL for obvious reasons. Reproduce code: --------------- /* PHP 4.3.4 MySQL 4.0.18 MyODBC 3.51.06 Win2K Professional */ $params[] = 1033; $params[] = "Test Label"; $query = "Insert into LABELS (id, code, label) Values (1,?,?)"; $RID = ODBC_Prepare($CID,$query); ODBC_Execute($RID,$params); Expected result: ---------------- Insert is successful using placeholders. Actual result: -------------- Warning: odbc_execute(): SQL error: [MySQL][ODBC 3.51 Driver][mysqld-4.0.18-max-debug]Duplicate entry '1' for key 1, SQL state 23000 in SQLExecute in c:\source\test.php on line 14 A record will be inserted into LABELS during the prepare: id=1 code=NULL label=NULL ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=27521&edit=1
