MySQL free ID
#1

Hello, I'm trying to combine two tables in MySQL.

Code:

Код:
new query[400];
mysql_format(handle, query, sizeof(query), "INSERT INTO Phones SET Number = '%i'", phone);
mysql_tquery(handle, query, "", ""); // Tried InsertPhone here but same result
InsertPhone(number, cache_insert_id());

public InsertPhone(number, lastid)
{
new query[400];
mysql_format(handle, query, sizeof(query), "INSERT INTO ServerObjects (number, phoneid) VALUES ('%i', '%d')", number, lastid);
mysql_query(handle, query);
}
But the last id is 0 everytime. In the table Phones I have an ID row with AUTO_INCREMENT.
In Server I can't make the 'phoneid' as AUTO_INCREMENT because I don't insert only phones...

Any help?
Reply
#2

cache_insert_id() must be used in the callback specified with mysql_tquery, but you didn't specify one. You're using the callback/function wrong. Let mysql_tquery call it.
Reply
#3

I've tried
Код:
mysql_tquery(handle, query, "InsertPhone", "id", number, cache_insert_id());
And don't work.
Reply
#4

Quote:
Originally Posted by HidroDF
Посмотреть сообщение
I've tried
Код:
mysql_tquery(handle, query, "InsertPhone", "id", number, cache_insert_id());
And don't work.
Put it directly:

mysql_format(handle, query, sizeof(query), "INSERT INTO ServerObjects (number, phoneid) VALUES ('%i', '%d')", number, cache_insert_id());
Reply
#5

Worked, thanks!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)