Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Question

Post Timeline

typo (throw new Exception)
Source Link
sbrbot
  • 6.5k
  • 7
  • 49
  • 83

In my MySQL database I have a table "table1" with unique constraint set on column "name" - I want to prevent duplicate names.

If there's already name 'John' in table this code:

$db=new mysqli(...);
$sql="INSERT INTO table1 SET id=10,name='John'";
if(!$db->query($sql))
{
 if($db->errno==1062)
 {
 throw new InsertNonUniqueException(...);
 }
 else
 {
 throw new InsertException(...);
 }
}

should throw InsertNonUniqueException() (my own exception). Instead, it throws InsertException().

Execution of query returns false and execution enters the if() loop. Also $db->row_affected is -1 but problem is that $db->errno is always O (it should be 1062)!!! So I can't detect that my insert error was caused by violating unique key constraint on name column!

I don't know why mysqli does not return 1062 code when unique key constraint violation occurs!

In my MySQL database I have a table "table1" with unique constraint set on column "name" - I want to prevent duplicate names.

If there's already name 'John' in table this code:

$db=new mysqli(...);
$sql="INSERT INTO table1 SET id=10,name='John'";
if(!$db->query($sql))
{
 if($db->errno==1062)
 {
 throw InsertNonUniqueException(...);
 }
 else
 {
 throw InsertException(...);
 }
}

should throw InsertNonUniqueException() (my own exception). Instead, it throws InsertException().

Execution of query returns false and execution enters the if() loop. Also $db->row_affected is -1 but problem is that $db->errno is always O (it should be 1062)!!! So I can't detect that my insert error was caused by violating unique key constraint on name column!

I don't know why mysqli does not return 1062 code when unique key constraint violation occurs!

In my MySQL database I have a table "table1" with unique constraint set on column "name" - I want to prevent duplicate names.

If there's already name 'John' in table this code:

$db=new mysqli(...);
$sql="INSERT INTO table1 SET id=10,name='John'";
if(!$db->query($sql))
{
 if($db->errno==1062)
 {
 throw new InsertNonUniqueException(...);
 }
 else
 {
 throw new InsertException(...);
 }
}

should throw InsertNonUniqueException() (my own exception). Instead, it throws InsertException().

Execution of query returns false and execution enters the if() loop. Also $db->row_affected is -1 but problem is that $db->errno is always O (it should be 1062)!!! So I can't detect that my insert error was caused by violating unique key constraint on name column!

I don't know why mysqli does not return 1062 code when unique key constraint violation occurs!

Notice removed Authoritative reference needed by Community Bot
Bounty Ended with no winning answer by Community Bot
Notice added Authoritative reference needed by sbrbot
Bounty Started worth 50 reputation by sbrbot
deleted 1 character in body
Source Link
sbrbot
  • 6.5k
  • 7
  • 49
  • 83

In my MySQL database I have a table "table1" with unique constraint set on column "name" - I want to prevent duplicate names.

If there's already name 'John' in table this code:

$db=new mysqli(...);
$sql="INSERT INTO table1 SET id=10,name='John')";name='John'";
if(!$db->query($sql))
{
 if($db->errno==1062)
 {
 throw InsertNonUniqueException(...);
 }
 else
 {
 throw InsertException(...);
 }
}

should throw InsertNonUniqueException() (my own exception). Instead, it throws InsertException().

Execution of query returns false and execution enters the if() loop. Also $db->row_affected is -1 but problem is that $db->errno is always O (it should be 1062)!!! So I can't detect that my insert error was caused by violating unique key constraint on name column!

I don't know why mysqli does not return 1062 code when unique key constraint violation occurs!

In my MySQL database I have a table "table1" with unique constraint set on column "name" - I want to prevent duplicate names.

If there's already name 'John' in table this code:

$db=new mysqli(...);
$sql="INSERT INTO table1 SET id=10,name='John')";
if(!$db->query($sql))
{
 if($db->errno==1062)
 {
 throw InsertNonUniqueException(...);
 }
 else
 {
 throw InsertException(...);
 }
}

should throw InsertNonUniqueException() (my own exception). Instead, it throws InsertException().

Execution of query returns false and execution enters the if() loop. Also $db->row_affected is -1 but problem is that $db->errno is always O (it should be 1062)!!! So I can't detect that my insert error was caused by violating unique key constraint on name column!

I don't know why mysqli does not return 1062 code when unique key constraint violation occurs!

In my MySQL database I have a table "table1" with unique constraint set on column "name" - I want to prevent duplicate names.

If there's already name 'John' in table this code:

$db=new mysqli(...);
$sql="INSERT INTO table1 SET id=10,name='John'";
if(!$db->query($sql))
{
 if($db->errno==1062)
 {
 throw InsertNonUniqueException(...);
 }
 else
 {
 throw InsertException(...);
 }
}

should throw InsertNonUniqueException() (my own exception). Instead, it throws InsertException().

Execution of query returns false and execution enters the if() loop. Also $db->row_affected is -1 but problem is that $db->errno is always O (it should be 1062)!!! So I can't detect that my insert error was caused by violating unique key constraint on name column!

I don't know why mysqli does not return 1062 code when unique key constraint violation occurs!

deleted 4 characters in body
Source Link
sbrbot
  • 6.5k
  • 7
  • 49
  • 83

In my MySQL database I have a table "table1" with unique constraint set on column "name" - I want to prevent duplicate names.

If there's already name 'John' in table this code:

$db=new mysqli(...);
$sql="INSERT INTO table1(id,name) VALUES(10SET id=10,'John'name='John')";
if(!$db->query($sql))
{
 if($db->errno==1062)
 {
 throw InsertNonUniqueException(...);
 }
 else
 {
 throw InsertException(...);
 }
}

should throw InsertNonUniqueException() (my own exception). Instead, it throws InsertException().

Execution of query returns false and execution enters the if() loop. Also $db->row_affected is -1 but problem is that $db->errno is always O (it should be 1062)!!! So I can't detect that my insert error was caused by violating unique key constraint on name column!

I don't know why mysqli does not return 1062 code when unique key constraint violation occurs!

In my MySQL database I have a table "table1" with unique constraint set on column "name" - I want to prevent duplicate names.

If there's already name 'John' in table this code:

$db=new mysqli(...);
$sql="INSERT INTO table1(id,name) VALUES(10,'John')";
if(!$db->query($sql))
{
 if($db->errno==1062)
 {
 throw InsertNonUniqueException(...);
 }
 else
 {
 throw InsertException(...);
 }
}

should throw InsertNonUniqueException() (my own exception). Instead, it throws InsertException().

Execution of query returns false and execution enters the if() loop. Also $db->row_affected is -1 but problem is that $db->errno is always O (it should be 1062)!!! So I can't detect that my insert error was caused by violating unique key constraint on name column!

I don't know why mysqli does not return 1062 code when unique key constraint violation occurs!

In my MySQL database I have a table "table1" with unique constraint set on column "name" - I want to prevent duplicate names.

If there's already name 'John' in table this code:

$db=new mysqli(...);
$sql="INSERT INTO table1 SET id=10,name='John')";
if(!$db->query($sql))
{
 if($db->errno==1062)
 {
 throw InsertNonUniqueException(...);
 }
 else
 {
 throw InsertException(...);
 }
}

should throw InsertNonUniqueException() (my own exception). Instead, it throws InsertException().

Execution of query returns false and execution enters the if() loop. Also $db->row_affected is -1 but problem is that $db->errno is always O (it should be 1062)!!! So I can't detect that my insert error was caused by violating unique key constraint on name column!

I don't know why mysqli does not return 1062 code when unique key constraint violation occurs!

Source Link
sbrbot
  • 6.5k
  • 7
  • 49
  • 83
Loading
default

AltStyle によって変換されたページ (->オリジナル) /