Perché ricevo un errore MySQL 1062?
-
22-10-2019 - |
Domanda
In una delle mie pagine php, continuo a ricevere il seguente errore:
SQLSTATE [23000]: Integrità violazione del vincolo: 1.062 voce duplicata '0' per la chiave 'primaria'
Non so perché o dove questo sta accadendo, che è il motivo sto inviando questa domanda.
penso che sta accadendo in questa sequenza di codice da qualche parte.
// create user
$STH = $DBH -> prepare( "insert into users ( display_name, oauth_provider, oauth_uid ) values ( :value, :oauth_provider, :id )" );
$STH -> bindParam( ':value', $value, PDO::PARAM_STR, 255 );
$STH -> bindParam( ':id', $oauth_id, PDO::PARAM_STR, 255 );
$STH -> bindParam( ':oauth_provider', $oauth_provider, PDO::PARAM_STR, 255 );
$STH -> execute();
// get newly created user
$STH = $DBH -> prepare( "select * from users where oauth_uid = :id and ( display_name = :value or email = :value ) and oauth_provider = :oauth_provider" );
$STH -> bindParam( ':value', $value, PDO::PARAM_STR, 255 );
$STH -> bindParam( ':id', $oauth_id, PDO::PARAM_STR, 255 );
$STH -> bindParam( ':oauth_provider', $oauth_provider, PDO::PARAM_STR, 255 );
$STH -> execute();
$result = $STH -> fetch();
// create settings record with 0's
$STH = $DBH -> prepare( "insert into settings ( col1, col2, col3, col4, col5, col6, col7, col8, col9, col10, user_id ) values ( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, :id )" );
$STH -> bindParam( ':id', $result["id"], PDO::PARAM_INT, 4 );
$STH -> execute();
Come faccio a sapere quale parte sta causando il problema?
Soluzione
è da MySQL alcuna relazione con il codice
cadere sulla colonna di primaria auto_increment alter chiave nuovamente a 1 e
aggiungere nuovamente il tasto
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow