For Programmers: Free Programming Magazines  


Home > Archive > PHP DB > April 2007 > auto_increment









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author auto_increment
Ron Piggott

2007-04-13, 9:57 pm

Does anyone see anything wrong with the $query syntax? Ron

mysql_connect(localhost,$username,$passw
ord);
@mysql_select_db($database) or die( "Unable to select database");
$query="ALTER TABLE sessions auto_increment = '1'";
mysql_query($query);
mysql_close();


David Robley

2007-04-14, 7:57 am

Ron Piggott wrote:

> Does anyone see anything wrong with the $query syntax? Ron
>
> mysql_connect(localhost,$username,$passw
ord);
> @mysql_select_db($database) or die( "Unable to select database");
> $query="ALTER TABLE sessions auto_increment = '1'";
> mysql_query($query);
> mysql_close();

The value would be an integer, not a string but that shouldn't cause a
problem. To quote the docs:

ALTER TABLE t2 AUTO_INCREMENT = value;

You cannot reset the counter to a value less than or equal to any that have
already been used. For MyISAM, if the value is less than or equal to the
maximum value currently in the AUTO_INCREMENT column, the value is reset to
the current maximum plus one.

It probably should be said that there is normally no reason to play with
auto-increment values.



Cheers
--
David Robley

An ulcer is what you get mountain climbing over molehills.
Today is Prickle-Prickle, the 31st day of Discord in the YOLD 3173.
Buesching, Logan J

2007-04-16, 6:57 pm

One of two things comes to my mind:

1.) auto_increment *might* have to be AUTO_INCREMENT, as that is how the
manual states it and *some* things in MySQL are case-sensitive (such as
table names).

2.) Make sure you have satisfied the following (From the MySQL manual):
--
You cannot reset the counter to a value less than or equal to any that
have already been used. For MyISAM, if the value is less than or equal
to the maximum value currently in the AUTO_INCREMENT column, the value
is reset to the current maximum plus one. For InnoDB, you can use ALTER
TABLE ... AUTO_INCREMENT =3D value as of MySQL 5.0.3, but if the value =
is
less than the current maximum value in the column, no error message is
given and the current sequence value is not changed.
--

If neither of these help, the actual error message may be of use.

-Logan

-----Original Message-----
From: Ron Piggott [mailto:ron.php@actsministries.org]=20
Sent: Friday, April 13, 2007 10:04 PM
To: PHP DB
Subject: auto_increment

Does anyone see anything wrong with the $query syntax? Ron

mysql_connect(localhost,$username,$passw
ord);
@mysql_select_db($database) or die( "Unable to select database");
$query=3D"ALTER TABLE sessions auto_increment =3D '1'";
mysql_query($query);
mysql_close();
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com