php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27920 Mutliple execution of SQL-INSERT by mssql_query
Submitted: 2004-04-08 09:16 UTC Modified: 2005-06-06 13:41 UTC
From: klaus dot kuehne at gga-hannover dot de Assigned:
Status: Not a bug Package: MSSQL related
PHP Version: 4.3.5 OS: Win 2000 Server
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: klaus dot kuehne at gga-hannover dot de
New email:
PHP Version: OS:

 

 [2004-04-08 09:16 UTC] klaus dot kuehne at gga-hannover dot de
Description:
------------
Depending of database and/or network charge, a single INSERT may be executed more than one time by mssql_query(), even if the first INSERT was executed successfully. The return code of mssql_query will be set to the last executed INSERT. 

In my case, a unique index prevented the subsequent INSERT's. This caused a lot of confusion, because the first INSERT was completed successful and mssql_query("INSERT INTO ...", $con) delivered "false" nevertheless. 

Problably, a longer delay time will be misinterpreted as a database lock, and mssql_query tries to encounter this by repetitions of the same INSERT. 

Couldn't find any workaround for this.

I recognized this bug in PHP versions 4.3.2 - 4.3.5. 

Expected result:
----------------
A succesful INSERT may not be repeated.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-04-08 11:19 UTC] sniper@php.net
Huh? How can this be PHP bug?

 [2004-04-08 16:01 UTC] fmk@php.net
mssql_query() does not do anything to the SQL statement, other than passing it on to the SQL server (once). There is no code to resubmit the same statement. The SQL statement can be a batch of inserts and or other commands, and mssql_query() will return false if one statement fails to execute on the server. A true value is returned if everything was executed with success but no data sets were returned (INSERT, UPDATE and DELETE statements). If a single statement returns a recordset mssql_query() will return a reource handle for the data.

I think this is a bug in either your PHP code or in the SQL statements (batches) you are sending to the server. Can you please provide some more info woth some code that reproduces the error.
 [2004-04-12 17:54 UTC] sniper@php.net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.


 [2005-06-06 04:42 UTC] orlov_oleg at hotmail dot ru
Yes, this bug exist in PHP 5.0.4 also
yesterday I detect bug.
this bug very strange.

$res = mysql_query("insert into page_sql (name) values('ZANUSSI')") or die("Query failed : " . mysql_error());
$id  = mysql_insert_id();
insert one time;

execute then any "select" 
"insert" again executed;

sorry for my English

Orlov Oleg.
 [2005-06-06 09:27 UTC] klaus dot kuehne at gga-hannover dot de
Hello Oleg,

in my case, this was a bug of myself (and of many other PHP developers, too).

The INSERT script was triggered by a FORM submit (&ltform action=insert.php>. Erroneously, I started the script a seond time by:
<input type="submit" onclick="document.forms[0].action='insert.php'; document.forms[0].submit();">

And so the same INSERT was performed two times. The output of the second call overwrote the output of the first call, and my control prints of the frist call disappeared. Very malicious, this effect.

You should proof your script for a double submit.

Regards,

Klaus K?hne
 [2005-06-06 09:34 UTC] derick@php.net
Bogus then.
 [2005-06-06 13:41 UTC] klaus dot kuehne at gga-hannover dot de
To express this clearer:

Instead of:
<input type="submit" onclick="document.forms[0].action='insert.php';
document.forms[0].submit();">

(this causes a double sumbmit)

you should write:

<input type="button" onclick="document.forms[0].action='insert.php';
document.forms[0].submit();">

Regards,

Klaus
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 03 05:01:29 2024 UTC