|  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
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.
Block user comment
Status: Assign to:
Bug Type:
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
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`)

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]);

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.


Add a Patch

Pull Requests

Add a Pull Request


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

Return Values
Returns TRUE on success or FALSE on failure. 

PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sun Feb 05 18:03:43 2023 UTC