开发者

Why am I getting a MySQL Error 1062?

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜