GetLastID();"/> GetLastID();">
Home > Database > Mysql Tutorial > mysql-Mysql的 auto_increment 使用问题

mysql-Mysql的 auto_increment 使用问题

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 09:35:01
Original
1251 people have browsed it

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>
Copy after login
<code></code>
Copy after login
Copy after login

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

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>
Copy after login
Copy after login
Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template