php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40969 Insert row with unique key violation, no error.
Submitted: 2007-03-31 19:03 UTC Modified: 2007-04-02 11:35 UTC
From: andrew dot craft at wyndhamworldwide dot com Assigned:
Status: Not a bug Package: MySQLi related
PHP Version: 5.2.1 OS: Windows XP SP2 32bit
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: andrew dot craft at wyndhamworldwide dot com
New email:
PHP Version: OS:

 

 [2007-03-31 19:03 UTC] andrew dot craft at wyndhamworldwide dot com
Description:
------------
I am using mysql 5.0.27.

There is a table that has a unique index on it. When inserting a new row that would violate the uniqueness using a prepared statement no errors/exceptions are raised. When looking at the query log the statement is prepared but no executions queries. Should there not be an exception raised for the error?

I did a google search and searched the bug database but did not find an existing issue.

Reproduce code:
---------------
CREATE TABLE `docs_classification` (
  `classification_id` smallint(6) NOT NULL auto_increment,
  `name` varchar(100) NOT NULL,
  `description` varchar(255) NOT NULL,
  `short_name` char(3) NOT NULL,
  `bit_value` int(11) NOT NULL,
  PRIMARY KEY  (`classification_id`),
  UNIQUE KEY `bit_value` (`bit_value`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=10 ;

//////////
First Run

array('test1', 'test1test1', 'TS1', '1'),
array('test2', 'test2test2', 'TS2', '2'),
array('test3', 'test3test3', 'TS3', '4')
);

$m = new mysqli('localhost', 'dbuser', '','dbname');
$sql = 'INSERT INTO dbtable '
' (classification_id, name, description, short_name, bit_value) '.
' VALUES (NULL, ?, ?, ?, ?)';

$stmt = $m->prepare($sql);

foreach ($a as $b)
{
	$stmt->bind_param('ssss', $b[0], $b[1], $b[2], $b[3]);
	$stmt->execute();
}

///////
Then repeat above code and no errors are raised.

Expected result:
----------------
Expected to be notified of the duplicate entry error in the bit_value field when re-running the code.

Actual result:
--------------
No errors or indication of any errors.

In the query log it shows the sql being prepared but no Execute commands.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-04-02 11:35 UTC] georg@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

http://www.php.net/manual/en/function.mysqli-stmt-execute.php:

Return Values
Returns TRUE on success or FALSE on failure. 


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Mar 10 21:01:30 2025 UTC