GetLastID();"/> GetLastID();">

>데이터 베이스 >MySQL 튜토리얼 >mysql-Mysql的 auto_increment 使用问题

mysql-Mysql的 auto_increment 使用问题

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB원래의
2016-06-06 09:35:011218검색

mysqlc++

我建表时将id设为了 auto increment , 后来有我使用时发现id应该是从1开始的,但是结果却是从2开始递增,我是使用的C++,下面的是我部分代码:

<code>        sql_->SetAutoCommit(0);        if(sql_->InsertUserLoginTable(id,"") == -1)        {            result = "regist faild1";        }        else        {            std::string ID = sql_->GetLastID();            std::cout InsertLoginInfoTable(ID, "", "", "", IMEI, BTMAC) == -1)            {                result = "regist faild2";            }            else if (sql_->InsertUserInfoTable(ID, FaceID, NickName, "", "", "3") == -1)            {                result = "regist faild3";            }            else if (sql_->InsertUserRecordTable(ID, RegistIP) == -1)            {                result = "regist faild4";            }            else            {                result = "regist success";            }        }        if(result == "regist success")        {            sql_->Commit(0);        }        else        {            sql_->Commit(1);        }        sql_->SetAutoCommit(1);</code>
<code></code>

其中有一些是我自己封装的方法,部分如下:

void SetAutoCommit(int i)
{
sql->AutoCommit(i);
}

int Commit(int i)
{
sql->CommitSQL(i);
}

void AutoCommit(int i)
{
mysql_autocommit(connection_,i);
}

int CommitSQL(int i)
{
if(i == 1)
{
mysql_rollback(connection_);
return -1;
}
else
{
mysql_commit(connection_);
return 0;
}
}

<code></code>
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.