문제

On one of my php pages, I keep getting the following error:

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '0' for key 'PRIMARY'

I don't know why or where this is happening, which is the reason I am posting this question.

I think it's happening in this code sequence somewhere.

// 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();

How do I find out which part is causing the problem?

도움이 되었습니까?

해결책

it is from mysql no relation to the code

drop the column of primary key alter auto_increment to 1 again and

add the key again

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top