[PHP] Challenging problem for you programing gurus...
Hi guys, I have come accross a small problem while trying to convert a java program to a PHP one my database table is like so * cno (int) name (varchar) lastname(varchar) etc etc * as you can see the details I take is name/lastname and customer number (cno) is automatically generated, now instead of using a auto increment a int was declared and this code was used ** synchronized(this) { rs=stmt.executeQuery(select max(cno)+1 from cust); } ** (for those of you who dont understand java) the synchronized keyword makes sure only one thread can work in the block of code between the { and } then it executes the query select max(cno)+1 from cust and stores the result in an array (like PHP) in rs. Basically, it just gets the next higher cno from the table cust. Then it enters the cno like this rs=cno,then name,lastname etc and then tells the customer that the data has been entered and his new customer number is rs. As you can see its a pain in the ass job which has to be changed, the problem is a few hundred records have already been entered, how do i use the current table BUT use the more useful auto increment and LAST_INSERT_ID() via PHP? The java servlet program which is handleing the requests is working fine, but I am want to convert it to a PHP program as paying for servlet hosting is upto 5-8 times more...and I aint rich, or even close to being rich :-( Please reply, ANY help appreciated and thanks in advance. Cheers, -Ryan.
Re: [PHP] Challenging problem for you programing gurus...
I didn't catch which database you are using, but you can alter a field in MySQL to add the auto_increment characteristic. Look into the alter table SQL statement. Happy hacking. Chris Ryan A wrote: how do i use the current table BUT use the more useful auto increment and LAST_INSERT_ID() via PHP? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Challenging problem for you programing gurus...
snip Chris Shiflett wrote: I didn't catch which database you are using, but you can alter a field in MySQL to add the auto_increment characteristic. Look into the alter table SQL statement. /snip And if you do that, there won't be any trouble with the existing IDs. mysql will grab the next higher number automatically. But test this on your own installation first, just to be sure ... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Chris,Matt-Re: [PHP] Challenging problem for you programing gurus
Thanks guys, I thought it would be much more complicated than that but will look into the alter table thing. Sorry forgot to mention in the first mail, I am using MySql as its the cheapest database to get from a hosting company,otherwise on my personal machine I use MySql and/or Oracle 7.3 (pirated version, I may not be rich but where theres a will theres a way :-) ) The reason I didnt alter it in the first place was that I was not sure if it would effect my current IDs, but since you guys say it wont i'll take your word for it. Cheers and thanks, -Ryan. snip Chris Shiflett wrote: I didn't catch which database you are using, but you can alter a field in MySQL to add the auto_increment characteristic. Look into the alter table SQL statement. /snip And if you do that, there won't be any trouble with the existing IDs. mysql will grab the next higher number automatically. But test this on your own installation first, just to be sure ... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Challenging problem for you programing gurus...
ALTER TABLE your_table CHANGE COLUMN old_column_name new_column_name NOT NULL AUTO_INCREMENT PRIMARY KEY; Then use mysql_insert_id() in your PHP code to retrieve the ID that is generated upon INSERTs. ---John Holmes... -Original Message- From: Ryan A [mailto:[EMAIL PROTECTED]] Sent: Saturday, September 28, 2002 12:17 PM To: [EMAIL PROTECTED] Subject: [PHP] Challenging problem for you programing gurus... Hi guys, I have come accross a small problem while trying to convert a java program to a PHP one my database table is like so * cno (int) name (varchar) lastname(varchar) etc etc * as you can see the details I take is name/lastname and customer number (cno) is automatically generated, now instead of using a auto increment a int was declared and this code was used ** synchronized(this) { rs=stmt.executeQuery(select max(cno)+1 from cust); } ** (for those of you who dont understand java) the synchronized keyword makes sure only one thread can work in the block of code between the { and } then it executes the query select max(cno)+1 from cust and stores the result in an array (like PHP) in rs. Basically, it just gets the next higher cno from the table cust. Then it enters the cno like this rs=cno,then name,lastname etc and then tells the customer that the data has been entered and his new customer number is rs. As you can see its a pain in the ass job which has to be changed, the problem is a few hundred records have already been entered, how do i use the current table BUT use the more useful auto increment and LAST_INSERT_ID() via PHP? The java servlet program which is handleing the requests is working fine, but I am want to convert it to a PHP program as paying for servlet hosting is upto 5-8 times more...and I aint rich, or even close to being rich :-( Please reply, ANY help appreciated and thanks in advance. Cheers, -Ryan. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] John Holmes-Re: [PHP] Challenging problem for you programing gurus...
Hey John, Thanks for the reply, Am a bit confused, 2 guys already gave me the advise you are giving me but you also say CHANGE COLUMN old_column_name new_column_name why to change the column name? dont I only have to change it from being an int to an Auto_Increment? Kindly reply, Cheers, -Ryan. ALTER TABLE your_table CHANGE COLUMN old_column_name new_column_name NOT NULL AUTO_INCREMENT PRIMARY KEY; Then use mysql_insert_id() in your PHP code to retrieve the ID that is generated upon INSERTs. ---John Holmes... -Original Message- From: Ryan A [mailto:[EMAIL PROTECTED]] Sent: Saturday, September 28, 2002 12:17 PM To: [EMAIL PROTECTED] Subject: [PHP] Challenging problem for you programing gurus... Hi guys, I have come accross a small problem while trying to convert a java program to a PHP one my database table is like so * cno (int) name (varchar) lastname(varchar) etc etc * as you can see the details I take is name/lastname and customer number (cno) is automatically generated, now instead of using a auto increment a int was declared and this code was used ** synchronized(this) { rs=stmt.executeQuery(select max(cno)+1 from cust); } ** (for those of you who dont understand java) the synchronized keyword makes sure only one thread can work in the block of code between the { and } then it executes the query select max(cno)+1 from cust and stores the result in an array (like PHP) in rs. Basically, it just gets the next higher cno from the table cust. Then it enters the cno like this rs=cno,then name,lastname etc and then tells the customer that the data has been entered and his new customer number is rs. As you can see its a pain in the ass job which has to be changed, the problem is a few hundred records have already been entered, how do i use the current table BUT use the more useful auto increment and LAST_INSERT_ID() via PHP? The java servlet program which is handleing the requests is working fine, but I am want to convert it to a PHP program as paying for servlet hosting is upto 5-8 times more...and I aint rich, or even close to being rich :-( Please reply, ANY help appreciated and thanks in advance. Cheers, -Ryan. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] John Holmes-Re: [PHP] Challenging problem for you programing gurus...
Hey John, Thanks for the reply, Am a bit confused, 2 guys already gave me the advise you are giving me but you also say CHANGE COLUMN old_column_name new_column_name why to change the column name? dont I only have to change it from being an int to an Auto_Increment? Yes. That's just the syntax. If you don't want to change the column name, then give the same column name for the new one...i.e., name it the _same thing_. ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php