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

Heim >Datenbank >MySQL-Tutorial >mysql-Mysql的 auto_increment 使用问题

mysql-Mysql的 auto_increment 使用问题

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-06 09:35:011218Durchsuche

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>
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn