Gossamer Forum
Home : General : Databases and SQL :

Mysql auto_increment

Quote Reply
Mysql auto_increment
Hello,

I'm having trouble getting information on tables in mysql,

I can't retrieve the number next in line for a field set to auto_increment.

I'm using LAST_INSERT_ID() in this fashion...

$sth = $dbh->do(<<End_SQL) or print "Couldn't prepare statement: $DBI::errstr; stopped";
INSERT INTO table1 VALUES (NULL,'Field1')
End_SQL


$sth = $dbh->do(<<End_SQL) or print "Couldn't prepare statement: $DBI::errstr; stopped";
INSERT INTO table2 VALUES ('',LAST_INSERT_ID(),'field1')
End_SQL

But I can't seem to get the generated number for field one into a $variable.

I shouldn't have to add a new entry into the table just to get the next number should I?

I can barely get the number of records with:

$sth = $dbh->do(<<End_SQL) or print "Couldn't prepare statement: $DBI::errstr; stopped";
SELECT * FROM table
End_SQL

$rows=$sth;



I'm having difficulty getting very simple information from these tables and have read the docs up & down.

Can someone help me put the peices together?

Thank you,
Tony
Subject Author Views Date
Thread Mysql auto_increment clearfox 18134 May 24, 2002, 1:06 AM
Post Re: [clearfox] Mysql auto_increment
Andy 17805 May 24, 2002, 1:15 AM
Thread Re: [clearfox] Mysql auto_increment
Paul 17938 May 24, 2002, 1:56 AM
Thread Re: [Paul] Mysql auto_increment
Wil 17848 May 24, 2002, 3:26 AM
Post Re: [Wil] Mysql auto_increment
Paul 17787 May 24, 2002, 3:31 AM
Thread Re: [Wil] Mysql auto_increment
Paul 17880 May 24, 2002, 3:33 AM
Thread Re: [Paul] Mysql auto_increment
Wil 17852 May 24, 2002, 4:40 AM
Thread Re: [Wil] Mysql auto_increment
Paul 17834 May 24, 2002, 4:43 AM
Thread Re: [Paul] Mysql auto_increment
ryel01 17782 May 26, 2002, 4:22 AM
Thread Re: [ryel01] Mysql auto_increment
Paul 17768 May 26, 2002, 4:38 AM
Thread Re: [Paul] Mysql auto_increment
clearfox 17757 Jun 3, 2002, 1:11 PM
Post Re: [clearfox] Mysql auto_increment
Paul 17710 Jun 3, 2002, 2:00 PM