php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27521 ODBC_Prepare forcing execution prior to ODBC_Execute with MySQL/MyODBC DB
Submitted: 2004-03-07 16:41 UTC Modified: 2004-03-08 08:09 UTC
From: getzeroedin at hotmail dot com Assigned:
Status: Closed Package: ODBC related
PHP Version: 4.3.4 OS: Win2000 Prof
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: getzeroedin at hotmail dot com
New email:
PHP Version: OS:

 

 [2004-03-07 16:41 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-03-08 06:44 UTC] sniper@php.net
If same code works with Mssql, what makes you think it's bug in PHP but not in mysql/myodbc ?

 [2004-03-08 08:09 UTC] getzeroedin at hotmail dot com
Yes. I've worked around it for now.  I'll take it up with MySQL/MyODBC.  Consider it closed.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Dec 04 17:00:01 2025 UTC